package portlet.tonghop;

import java.io.IOException;

import java.sql.Timestamp;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.StringTokenizer;
import java.util.TimeZone;

import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.el.MethodExpression;
import javax.el.ValueExpression;

import javax.faces.application.Application;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UISelectItems;
import javax.faces.context.FacesContext;
import javax.faces.convert.DateTimeConverter;

import javax.faces.event.ActionEvent;

import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;
import javax.portlet.PortletPreferences;
import javax.portlet.PortletRequest;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

import oracle.adf.model.binding.DCIteratorBinding;
import oracle.adf.view.rich.component.rich.data.RichColumn;
import oracle.adf.view.rich.component.rich.data.RichTable;
import oracle.adf.view.rich.component.rich.input.RichInputDate;
import oracle.adf.view.rich.component.rich.input.RichSelectOneChoice;
import oracle.adf.view.rich.component.rich.layout.RichPanelBorderLayout;
import oracle.adf.view.rich.component.rich.layout.RichPanelFormLayout;
import oracle.adf.view.rich.component.rich.layout.RichPanelGroupLayout;
import oracle.adf.view.rich.component.rich.layout.RichPanelLabelAndMessage;
import oracle.adf.view.rich.component.rich.layout.RichPanelTabbed;
import oracle.adf.view.rich.component.rich.layout.RichShowDetailItem;
import oracle.adf.view.rich.component.rich.nav.RichCommandButton;
import oracle.adf.view.rich.component.rich.nav.RichCommandLink;
import oracle.adf.view.rich.component.rich.nav.RichGoLink;
import oracle.adf.view.rich.component.rich.output.RichImage;
import oracle.adf.view.rich.component.rich.output.RichOutputText;
import oracle.adf.view.rich.context.AdfFacesContext;

import oracle.jbo.Row;
import oracle.jbo.RowSet;
import oracle.jbo.domain.ClobDomain;
import oracle.jbo.domain.Number;

import oracle.portlet.bridge.adf.application.ADFBridgePortlet;

import org.apache.myfaces.trinidad.event.DisclosureEvent;
import org.apache.myfaces.trinidad.model.RowKeySet;
import org.apache.myfaces.trinidad.model.RowKeySetImpl;
import org.apache.myfaces.trinidadinternal.taglib.util.MethodExpressionMethodBinding;

import portlet.common.Utils;
import portlet.common.search.AdvancedSearchGroup;
import portlet.common.search.AdvancedSearchItem;


public class TongHop extends ADFBridgePortlet {
    private RichPanelFormLayout chiTietPanel = new RichPanelFormLayout();
    private RichPanelFormLayout searchBaoCaoPanel = new RichPanelFormLayout();
    private RichPanelFormLayout searchCbttPanel = new RichPanelFormLayout();
    private RichPanelGroupLayout pagingBaoCaoPanel =
        new RichPanelGroupLayout();
    private RichPanelGroupLayout danhSachCbttPanel =
        new RichPanelGroupLayout();
    private RichPanelGroupLayout pagingCbttPanel = new RichPanelGroupLayout();
    private RichTable tableBaoCao = new RichTable();
    private RichOutputText outputTextTenDonVi = new RichOutputText();
    private RichPanelTabbed tabbedTongHop=new RichPanelTabbed();

    protected String getTitle(RenderRequest request) {
        // Get the customized title. This defaults to the declared title.
        PortletPreferences prefs = request.getPreferences();
        return prefs.getValue(PORTLETTITLE_KEY, super.getTitle(request));
    }
    public static final String APPLY_ACTION = "apply_action";
    public static final String OK_ACTION = "ok_action";
    public static final String PORTLETTITLE_KEY = "portletTitle";
    private static final String DEFAULT_LANGCODE = "vi";
    private final String SEARCH_ID_PREFIX = "search";
    private final String UPDATE_ID_PREFIX = "update";
    private final String ROW_KEY = "rowkey";
    private final String FILE_GROUP_ID_SUBFIX = "group";
    private final String FILE_LABEL_ID_SUBFIX = "label";
    private final String FILE_REMOVE_ID_SUBFIX = "remove";
    private final int DEFAULT_SIZE = 5;
    private final String LINK_DES = "des";
    private final String SEARCH_NAM = "baocao_search_nam";
    private final String SEARCH_TU_NGAY = "search_tu_ngay";
    private final String SEARCH_DEN_NGAY = "search_den_ngay";

    private String[] buildValueArray(String values) {
        if (values.indexOf(',') < 0) {
            return new String[] { values };
        }
        StringTokenizer st = new StringTokenizer(values, ",");
        String[] valueArray = new String[st.countTokens()];
        int i = 0;
        while (st.hasMoreTokens()) {
            valueArray[i] = st.nextToken().trim();
            i++;
        }
        return valueArray;
    }

    public void processAction(ActionRequest request,
                              ActionResponse response) throws PortletException,
                                                              IOException {
        request.setAttribute("javax.portlet.config", getPortletConfig());
        request.getPortletSession().setAttribute("processaction", 1);
        super.processAction(request, response);
    }

    public void render(RenderRequest request,
                       RenderResponse response) throws PortletException,
                                                       IOException {
        request.setAttribute("javax.portlet.config", getPortletConfig());
        super.render(request, response);
    }

    @Override
    protected void doView(RenderRequest renderRequest,
                          RenderResponse renderResponse) throws PortletException,
                                                                IOException {
        renderRequest.getPortletSession().setAttribute("reset", 1);
        checkParameter(renderRequest);
        super.doView(renderRequest, renderResponse);
    }

    public boolean checkParameter(RenderRequest request) {
        boolean check = true;
        String pLoaiDonViId = request.getParameter("loaidonviid");
        String pLangCode = request.getParameter("langcode");
        String pChiTietUrl = request.getParameter("chitieturl");
        String pHtFileServletUrl = request.getParameter("htfileservleturl");
        String pDonViId = request.getParameter("donviid");
        String pSoLuongBanGhi = request.getParameter("soluongbanghi");

        String sLoaiDonViId =
            (String)request.getPortletSession().getAttribute("loaidonviid");
        String sLangCode =
            (String)request.getPortletSession().getAttribute("langcode");
        String sChiTietUrl =
            (String)request.getPortletSession().getAttribute("chitieturl");
        String sDonViId =
            (String)request.getPortletSession().getAttribute("donviid");
        String sHtFileServletUrl =
            (String)request.getPortletSession().getAttribute("htfileservleturl");
        String sSoLuongBanGhi =
            (String)request.getPortletSession().getAttribute("soluongbanghi");
        if (pLangCode == null) {
            pLangCode = DEFAULT_LANGCODE;
        }
        if (sLoaiDonViId != null && pLoaiDonViId != null) {
            if (sLoaiDonViId.equals(pLoaiDonViId) == false) {
                check = false;
            }
        } else if (pLoaiDonViId != null) {
            check = false;
        } else if (sLoaiDonViId != null) {
            check = false;
        }

        if (sLangCode != null && pLangCode != null) {
            if (sLangCode.equals(pLangCode) == false) {
                check = false;
            }
        } else if (pLangCode != null) {
            check = false;
        } else if (sLangCode != null) {
            check = false;
        }

        if (sChiTietUrl != null && pChiTietUrl != null) {
            if (sChiTietUrl.equals(pChiTietUrl) == false) {
                check = false;
            }
        } else if (pChiTietUrl != null) {
            check = false;
        } else if (sChiTietUrl != null) {
            check = false;
        }

        if (sDonViId != null && pDonViId != null) {
            if (sDonViId.equals(pDonViId) == false) {
                check = false;
            }
        } else if (pDonViId != null) {
            check = false;
        } else if (sDonViId != null) {
            check = false;
        }

        if (sHtFileServletUrl != null && pHtFileServletUrl != null) {
            if (sHtFileServletUrl.equals(pHtFileServletUrl) == false) {
                check = false;
            }
        } else if (pHtFileServletUrl != null) {
            check = false;
        } else if (sHtFileServletUrl != null) {
            check = false;
        }

        if (sSoLuongBanGhi != null && pSoLuongBanGhi != null) {
            if (sSoLuongBanGhi.equals(pSoLuongBanGhi) == false) {
                check = false;
            }
        } else if (pSoLuongBanGhi != null) {
            check = false;
        } else if (sSoLuongBanGhi != null) {
            check = false;
        }
        request.getPortletSession().setAttribute("loaidonviid", pLoaiDonViId);
        request.getPortletSession().setAttribute("langcode", pLangCode);
        request.getPortletSession().setAttribute("chitieturl", pChiTietUrl);
        request.getPortletSession().setAttribute("donviid", pDonViId);
        request.getPortletSession().setAttribute("htfileservleturl",
                                                 pHtFileServletUrl);
        request.getPortletSession().setAttribute("soluongbanghi",
                                                 pSoLuongBanGhi);
        return check;
    }

    public String getResetForm() {
        PortletRequest request =
            (PortletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
        Integer reset =
            (Integer)request.getPortletSession().getAttribute("reset");
        if (reset != null && reset.intValue() == 1) {
            Integer resetTabbed =
                (Integer)request.getPortletSession().getAttribute("resettabbed");
            Integer processAction =
                (Integer)request.getPortletSession().getAttribute("processaction");
            if (processAction != null && processAction.intValue() == 1) {
            request.getPortletSession().setAttribute("processaction", 0);
            }else if (resetTabbed != null && resetTabbed.intValue() == 1) {
            List<UIComponent> listUI =tabbedTongHop.getChildren();
            boolean first=true;
            for(UIComponent ui:listUI){
                if (ui instanceof RichShowDetailItem) {
                    RichShowDetailItem rsdi = (RichShowDetailItem)ui;
                    if(first){
                    rsdi.setDisclosed(true);
                    first=false;
                    }else{
                    rsdi.setDisclosed(false);
                    }
                    AdfFacesContext.getCurrentInstance().addPartialTarget(rsdi);
                }
            }
            }else{
            request.getPortletSession().setAttribute("resettabbed", 1);
            }
            resetIteratorChiTiet(request);
            createFormChiTiet(request, getValueChiTiet(request));
            request.getPortletSession().setAttribute("reset", 0);

            request.getPortletSession().setAttribute("year", null);
            resetIteratorBaoCao(request);
            createFormBaoCao(request, 0);

            resetIteratorCbtt(request);
            createFormCbtt(request, 0);

            AdfFacesContext.getCurrentInstance().addPartialTarget(chiTietPanel);
            AdfFacesContext.getCurrentInstance().addPartialTarget(tableBaoCao);
            AdfFacesContext.getCurrentInstance().addPartialTarget(pagingBaoCaoPanel);
            AdfFacesContext.getCurrentInstance().addPartialTarget(danhSachCbttPanel);
            AdfFacesContext.getCurrentInstance().addPartialTarget(pagingCbttPanel);
        }
        return null;
    }

    private void createFormChiTiet(PortletRequest request,
                                   HashMap<String, Object> mapValue) {
        chiTietPanel.getChildren().clear();
        String tenDonVi = null;
        outputTextTenDonVi.setValue(null);
        if (mapValue != null) {
            String langCode =
                (String)request.getPortletSession().getAttribute("langcode");
            if (langCode == null) {
                langCode = DEFAULT_LANGCODE;
            }
            DCIteratorBinding truongTtView1Iterator =
                Utils.getIteratorBinding("DlctTruongTtView1Iterator");
            truongTtView1Iterator.setRangeSize(-1);
            Row[] rows = truongTtView1Iterator.getAllRowsInRange();
            if (rows == null) {
                rows = new Row[] { };
            }
            for (int i = 0; i < rows.length; i++) {
                String ten = (String)rows[i].getAttribute("TenTruong");
                Number kieuDuLieu = (Number)rows[i].getAttribute("KieuDuLieu");
                Number viTriHienThi =
                    (Number)rows[i].getAttribute("ViTriHienThi");
                Row loopRow = rows[i];
                Row rootRow = null;
                while (loopRow != null) {
                    rootRow = loopRow;
                    loopRow =
                            (Row)loopRow.getAttribute("DlctTruongTtTuIdDlctTruongTtView");
                }
                String rootId =
                    ((Number)rootRow.getAttribute("Id")).toString();
                if (viTriHienThi != null && kieuDuLieu != null) {
                    int viTri = viTriHienThi.intValue();
                    int kieu = kieuDuLieu.intValue();

                    if ((Utils.ENUM_VI_TRI_HIEN_THI.PORTLET_SELECT.getId() &
                         viTri) ==
                        Utils.ENUM_VI_TRI_HIEN_THI.PORTLET_SELECT.getId()) {
                        if (kieu == Utils.ENUM_KIEU_DU_LIEU.NUMBER.getId() ||
                            kieu == Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId() ||
                            kieu == Utils.ENUM_KIEU_DU_LIEU.DATE.getId()) {
                            Object valObject = mapValue.get(rootId);
                            if (valObject != null) {
                                if (tenDonVi == null) {
                                    tenDonVi = "" + valObject;
                                } else{
                                    tenDonVi = tenDonVi + "_" + valObject;
                                }
                                outputTextTenDonVi.setValue(tenDonVi);
                            }
                        }
                    } 
                    if ((Utils.ENUM_VI_TRI_HIEN_THI.PORTLET_INFO.getId() &
                                viTri) ==
                               Utils.ENUM_VI_TRI_HIEN_THI.PORTLET_INFO.getId()) {
                        if (kieu ==
                            Utils.ENUM_KIEU_DU_LIEU.IN_OUT_KIEM_TOAN_VIEN.getId() ||
                            kieu ==
                            Utils.ENUM_KIEU_DU_LIEU.KIEM_TOAN_VIEN.getId() ||
                            kieu ==
                            Utils.ENUM_KIEU_DU_LIEU.SL_KIEM_TOAN_VIEN.getId()) {
                            ten =
ten.replace("{0}", "" + Calendar.getInstance().get(Calendar.YEAR));
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.SL_KIEM_TOAN_VIEN.getId()) {
                                List<AdvancedSearchGroup> listASG =
                                    new ArrayList();
                                AdvancedSearchGroup asg =
                                    new AdvancedSearchGroup();
                                asg.setConjunction(asg.VC_CONJ_OR);
                                listASG.add(asg);
                                AdvancedSearchItem asi =
                                    new AdvancedSearchItem();
                                asg.getListChildren().add(asi);
                                asi.setItemName("NgayKetThuc");
                                asi.setOperator(asi.OPER_IS_BLANK);
                                asi.setRequired(true);
                                listASG.add(asg);
                                asi = new AdvancedSearchItem();
                                asg.getListChildren().add(asi);
                                asi.setConjunction(AdvancedSearchItem.VC_CONJ_OR);
                                asi.setItemName("NgayKetThuc");
                                asi.setOperator(asi.OPER_AFTER);
                                asi.setRequired(true);
                                asi.getListValue().add(0,
                                                       new oracle.jbo.domain.Date(new Timestamp(Calendar.getInstance().getTimeInMillis())));

                                asg =
                                    new AdvancedSearchGroup();
                                listASG.add(asg);
                                asi =
                                    new AdvancedSearchItem();
                                asg.getListChildren().add(asi);
                                asi.setItemName("DlctKiemToanVienView");
                                asi.setRequired(true);
                                asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                AdvancedSearchGroup asgChild =
                                    new AdvancedSearchGroup();
                                asi.getListChildren().add(asgChild);
                                AdvancedSearchItem asiChild =
                                    new AdvancedSearchItem();
                                asgChild.getListChildren().add(asiChild);
                asiChild.setItemName("TrangThai");
                asiChild.setRequired(true);
                asiChild.getListValue().add(0,
                                                new Number(Utils.ENUM_TRANG_THAI.CONG_BO.getId()));
                                Utils.searchadvanced("DlctKtvDvView1Iterator",
                                                     listASG);
                                DCIteratorBinding ktvDvView1Iterator =
                                    Utils.getIteratorBinding("DlctKtvDvView1Iterator");
                                if (ktvDvView1Iterator.getEstimatedRowCount() >
                                    0) {
                                    RichPanelLabelAndMessage label =
                                        new RichPanelLabelAndMessage();
                                    label.setLabel(ten);
                                    RichOutputText outputText =
                                        new RichOutputText();
                                    outputText.setValue(ktvDvView1Iterator.getEstimatedRowCount());
                                    label.getChildren().add(outputText);
                                    chiTietPanel.getChildren().add(label);
                                }
                            }
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.KIEM_TOAN_VIEN.getId()) {
                                RichTable tableKtv = new RichTable();
                                tableKtv.setAutoHeightRows(1000);
                                tableKtv.setRowBandingInterval(1);
                                tableKtv.setColumnResizing("disabled");
                                tableKtv.setContentDelivery("immediate");
                                tableKtv.setInlineStyle("height:auto !important;");
                                tableKtv.setFetchSize(1000);
                                tableKtv.setVar("row");
                                FacesContext fc =
                                    FacesContext.getCurrentInstance();
                                Application app = fc.getApplication();
                                ExpressionFactory elFactory =
                                    app.getExpressionFactory();
                                ELContext elContext = fc.getELContext();
                                RichColumn column = new RichColumn();
                                column.setNoWrap(false);
                                column.setSeparateRows(true);
                                column.setRowHeader(false);
                                column.setWidth("15");
                                column.setAlign(RichColumn.ALIGN_CENTER);
                                column.setHeaderText("STT");
                                RichOutputText outputText =
                                    new RichOutputText();
                                ValueExpression valueExp =
                                    elFactory.createValueExpression(elContext,
                                                                    "#{row['STT']}",
                                                                    Object.class);
                                outputText.setValueExpression("value",
                                                              valueExp);
                                column.getChildren().add(outputText);
                                tableKtv.getChildren().add(column);
                                {
                                    List<AdvancedSearchGroup> listASG =
                                        new ArrayList();
                                    AdvancedSearchGroup asgTrangThai =
                                        new AdvancedSearchGroup();
                                    listASG.add(asgTrangThai);
                                    AdvancedSearchItem asiTrangThai =
                                        new AdvancedSearchItem();
                                    asgTrangThai.getListChildren().add(asiTrangThai);
                                    asiTrangThai.setItemName("TrangThai");
                                    asiTrangThai.setRequired(true);
                                    asiTrangThai.getListValue().add(0,
                                                                    new Number(Utils.ENUM_TRANG_THAI.CONG_BO.getId()));
                                    AdvancedSearchGroup asgLoaiTruongTt =
                                        new AdvancedSearchGroup();
                                    listASG.add(asgLoaiTruongTt);
                                    AdvancedSearchItem asiLoaiTruongTt =
                                        new AdvancedSearchItem();
                                    asgLoaiTruongTt.getListChildren().add(asiLoaiTruongTt);
                                    asiLoaiTruongTt.setItemName("DlctLoaiTruongTt");
                                    asiLoaiTruongTt.setRequired(true);
                                    asiLoaiTruongTt.getListValue().add(0,
                                                                       new Number(Utils.ENUM_LOAI_TRUONG_TT.KIEM_TOAN_VIEN.getId()));
                                    if (langCode != null) {
                                        try {
                                            AdvancedSearchGroup asg =
                                                new AdvancedSearchGroup();
                                            listASG.add(asg);
                                            AdvancedSearchItem asi =
                                                new AdvancedSearchItem();
                                            asg.getListChildren().add(asi);
                                            asi.setItemName("DlctNgonNguView");
                                            asi.setRequired(true);
                                            asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                            AdvancedSearchGroup asgChild =
                                                new AdvancedSearchGroup();
                                            asi.getListChildren().add(asgChild);
                                            AdvancedSearchItem asiChild =
                                                new AdvancedSearchItem();
                                            asgChild.getListChildren().add(asiChild);
                                            asiChild.setItemName("Ma");
                                            asiChild.setRequired(true);
                                            asiChild.getListValue().add(langCode);
                                        } catch (Exception e) {
                                        }
                                    }
                                    Utils.searchadvanced("DlctTruongTtView2Iterator",
                                                         listASG);
                                    DCIteratorBinding truongTtView2Iterator =
                                        Utils.getIteratorBinding("DlctTruongTtView2Iterator");

                                    truongTtView2Iterator.setRangeSize(-1);
                                    Row[] rowsKtv =
                                        truongTtView2Iterator.getAllRowsInRange();
                                    if (rowsKtv == null) {
                                        rowsKtv = new Row[] { };
                                    }
                                    for (int j = 0; j < rowsKtv.length; j++) {
                                        String tenKtv =
                                            (String)rowsKtv[j].getAttribute("TenTruong");
                                        Number kieuDuLieuKtv =
                                            (Number)rowsKtv[j].getAttribute("KieuDuLieu");
                                        Number viTriHienThiKtv =
                                            (Number)rowsKtv[j].getAttribute("ViTriHienThi");
                                        Row loopRowKtv = rowsKtv[j];
                                        Row rootRowKtv = null;
                                        while (loopRowKtv != null) {
                                            rootRowKtv = loopRowKtv;
                                            loopRowKtv =
                                                    (Row)loopRowKtv.getAttribute("DlctTruongTtTuIdDlctTruongTtView");
                                        }
                                        if (viTriHienThiKtv != null &&
                                            kieuDuLieuKtv != null) {
                                            int viTriKtv =
                                                viTriHienThiKtv.intValue();
                                            int kieuKtv =
                                                kieuDuLieuKtv.intValue();
                                            if ((Utils.ENUM_VI_TRI_HIEN_THI.PORTLET_TABLE.getId() &
                                                 viTriKtv) ==
                                                Utils.ENUM_VI_TRI_HIEN_THI.PORTLET_TABLE.getId()) {
                                                String rootIdKtv =
                                                    ((Number)rootRowKtv.getAttribute("Id")).toString();
                                                if (kieuKtv ==
                                                    Utils.ENUM_KIEU_DU_LIEU.IN_OUT_KIEM_TOAN_VIEN.getId() ||
                                                    kieuKtv ==
                                                    Utils.ENUM_KIEU_DU_LIEU.KIEM_TOAN_VIEN.getId() ||
                                                    kieuKtv ==
                                                    Utils.ENUM_KIEU_DU_LIEU.SL_KIEM_TOAN_VIEN.getId()) {
                                                    // khong dua ra giao dien bang
                                                } else {
                                                    column = new RichColumn();
                                                    column.setNoWrap(false);
                                                    column.setHeaderText(tenKtv);
                                                    outputText =
                                                            new RichOutputText();
                                                    if (kieuKtv ==
                                                        Utils.ENUM_KIEU_DU_LIEU.DATE.getId()) {
                                                        DateTimeConverter converter =
                                                            (DateTimeConverter)FacesContext.getCurrentInstance().getApplication().createConverter("javax.faces.DateTime");
                                                        converter.setLocale(new Locale(langCode));
                                                        converter.setTimeZone(TimeZone.getTimeZone("GMT+7:00"));
                                                        converter.setType("date");
                                                        converter.setDateStyle("short");
                                                        outputText.setConverter(converter);
                                                    }
                                                    valueExp =
                                                            elFactory.createValueExpression(elContext,
                                                                                            "#{row['" +
                                                                                            rootIdKtv +
                                                                                            "']}",
                                                                                            Object.class);
                                                    outputText.setValueExpression("value",
                                                                                  valueExp);
                                                    column.getChildren().add(outputText);
                                                    tableKtv.getChildren().add(column);
                                                }
                                            }
                                        }
                                    }
                                }
                                {

                                    List<AdvancedSearchGroup> listASG =
                                        new ArrayList();
                                    AdvancedSearchGroup asg =
                                        new AdvancedSearchGroup();
                                    asg.setConjunction(asg.VC_CONJ_OR);
                                    listASG.add(asg);
                                    AdvancedSearchItem asi =
                                        new AdvancedSearchItem();
                                    asg.getListChildren().add(asi);
                                    asi.setItemName("NgayKetThuc");
                                    asi.setOperator(asi.OPER_IS_BLANK);
                                    asi.setRequired(true);
                                    listASG.add(asg);
                                    asi = new AdvancedSearchItem();
                                    asg.getListChildren().add(asi);
                                    asi.setConjunction(AdvancedSearchItem.VC_CONJ_OR);
                                    asi.setItemName("NgayKetThuc");
                                    asi.setOperator(asi.OPER_AFTER);
                                    asi.setRequired(true);
                                    asi.getListValue().add(0,
                                                           new oracle.jbo.domain.Date(new Timestamp(Calendar.getInstance().getTimeInMillis())));

                                    asg =
                                        new AdvancedSearchGroup();
                                    listASG.add(asg);
                                    asi =
                                        new AdvancedSearchItem();
                                    asg.getListChildren().add(asi);
                                    asi.setItemName("DlctKiemToanVienView");
                                    asi.setRequired(true);
                                    asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                    AdvancedSearchGroup asgChild =
                                        new AdvancedSearchGroup();
                                    asi.getListChildren().add(asgChild);
                                    AdvancedSearchItem asiChild =
                                        new AdvancedSearchItem();
                                    asgChild.getListChildren().add(asiChild);
                                    asiChild.setItemName("TrangThai");
                                    asiChild.setRequired(true);
                                    asiChild.getListValue().add(0,
                                                    new Number(Utils.ENUM_TRANG_THAI.CONG_BO.getId()));
                                    Utils.searchadvanced("DlctKtvDvView1Iterator",
                                                         listASG);
                                    DCIteratorBinding ktvDvView1Iterator =
                                        Utils.getIteratorBinding("DlctKtvDvView1Iterator");
                                    ktvDvView1Iterator.setRangeSize(-1);
                                    Row[] rowsKtv =
                                        ktvDvView1Iterator.getAllRowsInRange();
                                    List<Map<String, Object>> listValue =
                                        new ArrayList();
                                    if (rowsKtv != null &&
                                        rowsKtv.length > 0) {
                                        for (int j = 0; j < rowsKtv.length;
                                             j++) {
                                            ktvDvView1Iterator.setCurrentRowIndexInRange(j);
                                            Row kiemToanVienRow =
                                                (Row)ktvDvView1Iterator.getCurrentRow().getAttribute("DlctKiemToanVienView");
                                            if (kiemToanVienRow != null) {
                                                RowSet rowSetGtTt =
                                                    (RowSet)kiemToanVienRow.getAttribute("DlctGtKtvTtView");
                                                if (rowSetGtTt != null) {
                                                    rowSetGtTt.setRangeSize(-1);
                                                    Row[] rowsGtTt =
                                                        rowSetGtTt.getAllRowsInRange();
                                                    if (rowsGtTt == null) {
                                                        rowsGtTt =
                                                                new Row[] { };
                                                    }
                                                    HashMap<String, Object> mapValueKtv =
                                                        new HashMap();
                                                    mapValueKtv.put("STT",
                                                                    j + 1);
                                                    for (int k = 0;
                                                         k < rowsGtTt.length;
                                                         k++) {
                                                        Row truongTtRow =
                                                            (Row)rowsGtTt[k].getAttribute("DlctTruongTtView");
                                                        if (truongTtRow !=
                                                            null) {
                                                            Number idKtvTt =
                                                                (Number)truongTtRow.getAttribute("Id");
                                                            Number kieuDuLieuKtvTt =
                                                                (Number)truongTtRow.getAttribute("KieuDuLieu");
                                                            if (idKtvTt !=
                                                                null &&
                                                                kieuDuLieuKtvTt !=
                                                                null) {
                                                                int kieuKtvTt =
                                                                    kieuDuLieuKtvTt.intValue();
                                                                if (kieuKtvTt ==
                                                                    Utils.ENUM_KIEU_DU_LIEU.NUMBER.getId()) {
                                                                    Number valNumber =
                                                                        (Number)rowsGtTt[k].getAttribute("ValNumber");
                                                                    if (valNumber !=
                                                                        null) {
                                                                        mapValueKtv.put(idKtvTt.toString(),
                                                                                        valNumber.toString());
                                                                    }
                                                                }
                                                                if (kieuKtvTt ==
                                                                    Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId()) {
                                                                    String valVarchar =
                                                                        (String)rowsGtTt[k].getAttribute("ValVarchar");
                                                                    if (valVarchar !=
                                                                        null) {
                                                                        mapValueKtv.put(idKtvTt.toString(),
                                                                                        valVarchar);
                                                                    }
                                                                }
                                                                if (kieuKtvTt ==
                                                                    Utils.ENUM_KIEU_DU_LIEU.LINK.getId()) {
                                                                    String valVarchar =
                                                                        (String)rowsGtTt[k].getAttribute("ValVarchar");
                                                                    if (valVarchar !=
                                                                        null) {
                                                                        mapValueKtv.put(idKtvTt.toString(),
                                                                                        valVarchar);
                                                                    }
                                                                }
                                                                if (kieuKtvTt ==
                                                                    Utils.ENUM_KIEU_DU_LIEU.EMAIL.getId()) {
                                                                    String valVarchar =
                                                                        (String)rowsGtTt[k].getAttribute("ValVarchar");
                                                                    if (valVarchar !=
                                                                        null) {
                                                                        mapValueKtv.put(idKtvTt.toString(),
                                                                                        valVarchar);
                                                                    }
                                                                }
                                                                if (kieuKtvTt ==
                                                                    Utils.ENUM_KIEU_DU_LIEU.DATE.getId()) {
                                                                    oracle.jbo.domain.Date valDate =
                                                                        (oracle.jbo.domain.Date)rowsGtTt[k].getAttribute("ValDate");
                                                                    if (valDate !=
                                                                        null) {
                                                                        java.util.Date date =
                                                                            valDate.dateValue();
                                                                        if (date !=
                                                                            null) {
                                                                            mapValueKtv.put(idKtvTt.toString(),
                                                                                            date);
                                                                        }
                                                                    }
                                                                }
                                                                if (kieuKtvTt ==
                                                                    Utils.ENUM_KIEU_DU_LIEU.CLOB.getId()) {
                                                                    ClobDomain valClob =
                                                                        (ClobDomain)rowsGtTt[k].getAttribute("ValClob");
                                                                    if (valClob !=
                                                                        null) {
                                                                        mapValueKtv.put(idKtvTt.toString(),
                                                                                        valClob.toString());
                                                                    }
                                                                }
                                                                if (kieuKtvTt ==
                                                                    Utils.ENUM_KIEU_DU_LIEU.FILE.getId()) {
                                                                    Row fileViewRow =
                                                                        (Row)rowsGtTt[k].getAttribute("HtFileView");
                                                                    if (fileViewRow !=
                                                                        null) {
                                                                        String tenFile =
                                                                            (String)fileViewRow.getAttribute("TenFile");
                                                                        if (tenFile !=
                                                                            null) {
                                                                            mapValueKtv.put(idKtvTt.toString(),
                                                                                            tenFile);
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                    listValue.add(mapValueKtv);
                                                }
                                            }
                                        }
                                        tableKtv.setValue(listValue);
                                        RichPanelLabelAndMessage label =
                                            new RichPanelLabelAndMessage();
                                        label.setLabel(ten);
                                        label.getChildren().add(tableKtv);
                                        chiTietPanel.getChildren().add(label);
                                    }
                                }
                            }
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.IN_OUT_KIEM_TOAN_VIEN.getId()) {
                                RichTable tableKtv = new RichTable();
                                tableKtv.setAutoHeightRows(1000);
                                tableKtv.setRowBandingInterval(1);
                                tableKtv.setColumnResizing("disabled");
                                tableKtv.setContentDelivery("immediate");
                                tableKtv.setInlineStyle("height:auto !important;");
                                tableKtv.setVar("row");
                                tableKtv.setFetchSize(1000);

                                FacesContext fc =
                                    FacesContext.getCurrentInstance();
                                Application app = fc.getApplication();
                                ExpressionFactory elFactory =
                                    app.getExpressionFactory();
                                ELContext elContext = fc.getELContext();
                                RichColumn column = new RichColumn();
                                column.setNoWrap(false);
                                column.setSeparateRows(true);
                                column.setRowHeader(false);
                                column.setHeaderText(getResource("TANG"));
                                RichOutputText outputText =
                                    new RichOutputText();
                                ValueExpression valueExp =
                                    elFactory.createValueExpression(elContext,
                                                                    "#{row['Tang']}",
                                                                    Object.class);
                                outputText.setValueExpression("value",
                                                              valueExp);
                                column.getChildren().add(outputText);
                                tableKtv.getChildren().add(column);
                                column = new RichColumn();
                                column.setNoWrap(false);
                                column.setHeaderText(getResource("GIAM"));
                                outputText = new RichOutputText();
                                valueExp =
                                        elFactory.createValueExpression(elContext,
                                                                        "#{row['Giam']}",
                                                                        Object.class);
                                outputText.setValueExpression("value",
                                                              valueExp);
                                column.getChildren().add(outputText);
                                tableKtv.getChildren().add(column);
                                column = new RichColumn();
                                column.setNoWrap(false);
                                column.setHeaderText(getResource("THOI_GIAN"));
                                outputText = new RichOutputText();
                                {
                                    DateTimeConverter converter =
                                        (DateTimeConverter)FacesContext.getCurrentInstance().getApplication().createConverter("javax.faces.DateTime");
                                    converter.setLocale(new Locale(langCode));
                                    converter.setTimeZone(TimeZone.getTimeZone("GMT+7:00"));
                                    converter.setType("date");
                                    converter.setDateStyle("short");
                                    outputText.setConverter(converter);
                                }
                                valueExp =
                                        elFactory.createValueExpression(elContext,
                                                                        "#{row['ThoiGian']}",
                                                                        Object.class);
                                outputText.setValueExpression("value",
                                                              valueExp);
                                column.getChildren().add(outputText);
                                tableKtv.getChildren().add(column);
                                List<String> listSelect = new ArrayList();
                                {
                                    List<AdvancedSearchGroup> listASG =
                                        new ArrayList();
                                    AdvancedSearchGroup asgTrangThai =
                                        new AdvancedSearchGroup();
                                    listASG.add(asgTrangThai);
                                    AdvancedSearchItem asiTrangThai =
                                        new AdvancedSearchItem();
                                    asgTrangThai.getListChildren().add(asiTrangThai);
                                    asiTrangThai.setItemName("TrangThai");
                                    asiTrangThai.setRequired(true);
                                    asiTrangThai.getListValue().add(0,
                                                                    new Number(Utils.ENUM_TRANG_THAI.CONG_BO.getId()));
                                    AdvancedSearchGroup asgLoaiTruongTt =
                                        new AdvancedSearchGroup();
                                    listASG.add(asgLoaiTruongTt);
                                    AdvancedSearchItem asiLoaiTruongTt =
                                        new AdvancedSearchItem();
                                    asgLoaiTruongTt.getListChildren().add(asiLoaiTruongTt);
                                    asiLoaiTruongTt.setItemName("DlctLoaiTruongTt");
                                    asiLoaiTruongTt.setRequired(true);
                                    asiLoaiTruongTt.getListValue().add(0,
                                                                       new Number(Utils.ENUM_LOAI_TRUONG_TT.KIEM_TOAN_VIEN.getId()));
                                    if (langCode != null) {
                                        try {
                                            AdvancedSearchGroup asg =
                                                new AdvancedSearchGroup();
                                            listASG.add(asg);
                                            AdvancedSearchItem asi =
                                                new AdvancedSearchItem();
                                            asg.getListChildren().add(asi);
                                            asi.setItemName("DlctNgonNguView");
                                            asi.setRequired(true);
                                            asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                            AdvancedSearchGroup asgChild =
                                                new AdvancedSearchGroup();
                                            asi.getListChildren().add(asgChild);
                                            AdvancedSearchItem asiChild =
                                                new AdvancedSearchItem();
                                            asgChild.getListChildren().add(asiChild);
                                            asiChild.setItemName("Ma");
                                            asiChild.setRequired(true);
                                            asiChild.getListValue().add(langCode);
                                        } catch (Exception e) {
                                        }
                                    }
                                    Utils.searchadvanced("DlctTruongTtView2Iterator",
                                                         listASG);
                                    DCIteratorBinding truongTtView2Iterator =
                                        Utils.getIteratorBinding("DlctTruongTtView2Iterator");
                                    truongTtView2Iterator.setRangeSize(-1);
                                    Row[] rowsKtv =
                                        truongTtView2Iterator.getAllRowsInRange();
                                    if (rowsKtv == null) {
                                        rowsKtv = new Row[] { };
                                    }
                                    for (int j = 0; j < rowsKtv.length; j++) {
                                        Number kieuDuLieuKtv =
                                            (Number)rowsKtv[j].getAttribute("KieuDuLieu");
                                        Number viTriHienThiKtv =
                                            (Number)rowsKtv[j].getAttribute("ViTriHienThi");
                                        Row loopRowKtv = rowsKtv[j];
                                        Row rootRowKtv = null;
                                        while (loopRowKtv != null) {
                                            rootRowKtv = loopRowKtv;
                                            loopRowKtv =
                                                    (Row)loopRowKtv.getAttribute("DlctTruongTtTuIdDlctTruongTtView");
                                        }
                                        if (viTriHienThiKtv != null &&
                                            kieuDuLieuKtv != null) {
                                            int viTriKtv =
                                                viTriHienThiKtv.intValue();
                                            int kieuKtv =
                                                kieuDuLieuKtv.intValue();
                                            if ((Utils.ENUM_VI_TRI_HIEN_THI.PORTLET_SELECT.getId() &
                                                 viTriKtv) ==
                                                Utils.ENUM_VI_TRI_HIEN_THI.PORTLET_SELECT.getId()) {
                                                String rootIdKtv =
                                                    ((Number)rootRowKtv.getAttribute("Id")).toString();
                                                if (kieuKtv ==
                                                    Utils.ENUM_KIEU_DU_LIEU.IN_OUT_KIEM_TOAN_VIEN.getId() ||
                                                    kieuKtv ==
                                                    Utils.ENUM_KIEU_DU_LIEU.KIEM_TOAN_VIEN.getId() ||
                                                    kieuKtv ==
                                                    Utils.ENUM_KIEU_DU_LIEU.SL_KIEM_TOAN_VIEN.getId()) {
                                                    // khong dua ra giao dien bang
                                                } else {
                                                    if (listSelect.contains("" +
                                                                            rootIdKtv) ==
                                                        false) {
                                                        listSelect.add("" +
                                                                       rootIdKtv);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                {
                                    Calendar calendar = Calendar.getInstance();
                                    oracle.jbo.domain.Date current =
                                        new oracle.jbo.domain.Date(new Timestamp(calendar.getTimeInMillis()));
                                    SimpleDateFormat dateFormat =
                                        new SimpleDateFormat("yyyy/MM/dd");
                                    java.util.Date javaDate = null;
                                    try {
                                        javaDate =
                                                dateFormat.parse(calendar.get(Calendar.YEAR) +
                                                                 "/01/01");
                                    } catch (ParseException e) {
                                    }
                                    oracle.jbo.domain.Date dauNam =
                                        new oracle.jbo.domain.Date(new Timestamp(javaDate.getTime()));
                                    List<AdvancedSearchGroup> listASG =
                                        new ArrayList();
                                    AdvancedSearchGroup asg =
                                        new AdvancedSearchGroup();
                                    listASG.add(asg);
                                    AdvancedSearchItem asi =
                                        new AdvancedSearchItem();
                                    asg.getListChildren().add(asi);
                                    asi.setItemName("NgayBatDau");
                                    asi.setOperator(asi.OPER_AFTER);
                                    asi.setConjunction(asi.VC_CONJ_OR);
                                    asi.setRequired(true);
                                    asi.getListValue().add(0, dauNam);
                                    asi = new AdvancedSearchItem();
                                    asg.getListChildren().add(asi);
                                    asi.setItemName("NgayKetThuc");
                                    asi.setOperator(asi.OPER_AFTER);
                                    asi.setConjunction(asi.VC_CONJ_OR);
                                    asi.setRequired(true);
                                    asi.getListValue().add(0, dauNam);
                                    asg =
                                        new AdvancedSearchGroup();
                                    listASG.add(asg);
                                    asi =
                                        new AdvancedSearchItem();
                                    asg.getListChildren().add(asi);
                                    asi.setItemName("DlctKiemToanVienView");
                                    asi.setRequired(true);
                                    asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                    AdvancedSearchGroup asgChild =
                                        new AdvancedSearchGroup();
                                    asi.getListChildren().add(asgChild);
                                    AdvancedSearchItem asiChild =
                                        new AdvancedSearchItem();
                                    asgChild.getListChildren().add(asiChild);
                                    asiChild.setItemName("TrangThai");
                                    asiChild.setRequired(true);
                                    asiChild.getListValue().add(0,
                                                    new Number(Utils.ENUM_TRANG_THAI.CONG_BO.getId()));
                                    Utils.searchadvanced("DlctKtvDvView1Iterator",
                                                         listASG);
                                    DCIteratorBinding ktvDvView1Iterator =
                                        Utils.getIteratorBinding("DlctKtvDvView1Iterator");
                                    ktvDvView1Iterator.setRangeSize(-1);
                                    Row[] rowsKtv =
                                        ktvDvView1Iterator.getAllRowsInRange();
                                    List<Map<String, Object>> listValue =
                                        new ArrayList();
                                    if (rowsKtv != null &&
                                        rowsKtv.length > 0) {
                                        for (int j = 0; j < rowsKtv.length;
                                             j++) {
                                            ktvDvView1Iterator.setCurrentRowIndexInRange(j);
                                            Row kiemToanVienRow =
                                                (Row)ktvDvView1Iterator.getCurrentRow().getAttribute("DlctKiemToanVienView");
                                            if (kiemToanVienRow != null) {
                                                RowSet rowSetGtTt =
                                                    (RowSet)kiemToanVienRow.getAttribute("DlctGtKtvTtView");
                                                if (rowSetGtTt != null) {
                                                    rowSetGtTt.setRangeSize(-1);
                                                    Row[] rowsGtTt =
                                                        rowSetGtTt.getAllRowsInRange();
                                                    if (rowsGtTt == null) {
                                                        rowsGtTt =
                                                                new Row[] { };
                                                    }
                                                    HashMap<String, Object> mapValueKtv =
                                                        new HashMap();
                                                    for (int k = 0;
                                                         k < rowsGtTt.length;
                                                         k++) {
                                                        Row truongTtRow =
                                                            (Row)rowsGtTt[k].getAttribute("DlctTruongTtView");
                                                        if (truongTtRow !=
                                                            null) {
                                                            Number idKtvTt =
                                                                (Number)truongTtRow.getAttribute("Id");
                                                            Number kieuDuLieuKtvTt =
                                                                (Number)truongTtRow.getAttribute("KieuDuLieu");
                                                            if (idKtvTt !=
                                                                null &&
                                                                kieuDuLieuKtvTt !=
                                                                null) {
                                                                int kieuKtvTt =
                                                                    kieuDuLieuKtvTt.intValue();
                                                                if (kieuKtvTt ==
                                                                    Utils.ENUM_KIEU_DU_LIEU.NUMBER.getId()) {
                                                                    Number valNumber =
                                                                        (Number)rowsGtTt[k].getAttribute("ValNumber");
                                                                    if (valNumber !=
                                                                        null) {
                                                                        mapValueKtv.put(idKtvTt.toString(),
                                                                                        valNumber.toString());
                                                                    }
                                                                }
                                                                if (kieuKtvTt ==
                                                                    Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId()) {
                                                                    String valVarchar =
                                                                        (String)rowsGtTt[k].getAttribute("ValVarchar");
                                                                    if (valVarchar !=
                                                                        null) {
                                                                        mapValueKtv.put(idKtvTt.toString(),
                                                                                        valVarchar);
                                                                    }
                                                                }
                                                                if (kieuKtvTt ==
                                                                    Utils.ENUM_KIEU_DU_LIEU.LINK.getId()) {
                                                                    String valVarchar =
                                                                        (String)rowsGtTt[k].getAttribute("ValVarchar");
                                                                    if (valVarchar !=
                                                                        null) {
                                                                        mapValueKtv.put(idKtvTt.toString(),
                                                                                        valVarchar);
                                                                    }
                                                                }
                                                                if (kieuKtvTt ==
                                                                    Utils.ENUM_KIEU_DU_LIEU.EMAIL.getId()) {
                                                                    String valVarchar =
                                                                        (String)rowsGtTt[k].getAttribute("ValVarchar");
                                                                    if (valVarchar !=
                                                                        null) {
                                                                        mapValueKtv.put(idKtvTt.toString(),
                                                                                        valVarchar);
                                                                    }
                                                                }
                                                                if (kieuKtvTt ==
                                                                    Utils.ENUM_KIEU_DU_LIEU.DATE.getId()) {
                                                                    oracle.jbo.domain.Date valDate =
                                                                        (oracle.jbo.domain.Date)rowsGtTt[k].getAttribute("ValDate");
                                                                    if (valDate !=
                                                                        null) {
                                                                        java.util.Date date =
                                                                            valDate.dateValue();
                                                                        if (date !=
                                                                            null) {
                                                                            mapValueKtv.put(idKtvTt.toString(),
                                                                                            date);
                                                                        }
                                                                    }
                                                                }
                                                                if (kieuKtvTt ==
                                                                    Utils.ENUM_KIEU_DU_LIEU.CLOB.getId()) {
                                                                    ClobDomain valClob =
                                                                        (ClobDomain)rowsGtTt[k].getAttribute("ValClob");
                                                                    if (valClob !=
                                                                        null) {
                                                                        mapValueKtv.put(idKtvTt.toString(),
                                                                                        valClob.toString());
                                                                    }
                                                                }
                                                                if (kieuKtvTt ==
                                                                    Utils.ENUM_KIEU_DU_LIEU.FILE.getId()) {
                                                                    Row fileViewRow =
                                                                        (Row)rowsGtTt[k].getAttribute("HtFileView");
                                                                    if (fileViewRow !=
                                                                        null) {
                                                                        String tenFile =
                                                                            (String)fileViewRow.getAttribute("TenFile");
                                                                        if (tenFile !=
                                                                            null) {
                                                                            mapValueKtv.put(idKtvTt.toString(),
                                                                                            tenFile);
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                    {
                                                        oracle.jbo.domain.Date valDateBatDau =
                                                            (oracle.jbo.domain.Date)ktvDvView1Iterator.getCurrentRow().getAttribute("NgayBatDau");
                                                        oracle.jbo.domain.Date valDateKetThuc =
                                                            (oracle.jbo.domain.Date)ktvDvView1Iterator.getCurrentRow().getAttribute("NgayKetThuc");
                                                        if (valDateKetThuc ==
                                                            null ||
                                                            valDateKetThuc.dateValue().after(current.dateValue())) {
                                                            String selectValue =
                                                                "";
                                                            for (String str :
                                                                 listSelect) {
                                                                Object obj =
                                                                    mapValueKtv.get(str);
                                                                if (obj !=
                                                                    null) {
                                                                    selectValue =
                                                                            selectValue +
                                                                            " " +
                                                                            obj;
                                                                }
                                                            }
                                                            if (valDateBatDau !=
                                                                null &&
                                                                selectValue.isEmpty() ==
                                                                false) {
                                                                mapValueKtv =
                                                                        new HashMap();
                                                                java.util.Date date =
                                                                    valDateBatDau.dateValue();
                                                                mapValueKtv.put("Tang",
                                                                                selectValue);
                                                                if (date !=
                                                                    null) {
                                                                    mapValueKtv.put("ThoiGian",
                                                                                    date);
                                                                }
                                                                listValue.add(mapValueKtv);
                                                            }
                                                        } else {
                                                            String selectValue =
                                                                "";
                                                            for (String str :
                                                                 listSelect) {
                                                                Object obj =
                                                                    mapValueKtv.get(str);
                                                                if (obj !=
                                                                    null) {
                                                                    selectValue =
                                                                            selectValue +
                                                                            " " +
                                                                            obj;
                                                                }
                                                            }
                                                            if (valDateKetThuc !=
                                                                null &&
                                                                selectValue.isEmpty() ==
                                                                false) {
                                                                mapValueKtv =
                                                                        new HashMap();
                                                                java.util.Date date =
                                                                    valDateKetThuc.dateValue();
                                                                mapValueKtv.put("Giam",
                                                                                selectValue);
                                                                if (date !=
                                                                    null) {
                                                                    mapValueKtv.put("ThoiGian",
                                                                                    date);
                                                                }
                                                                listValue.add(mapValueKtv);
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        Collections.sort(listValue,
                                                         new ThoiGianComparator());
                                        tableKtv.setValue(listValue);
                                        RichPanelLabelAndMessage label =
                                            new RichPanelLabelAndMessage();
                                        label.setLabel(ten);
                                        label.getChildren().add(tableKtv);
                                        chiTietPanel.getChildren().add(label);
                                    }
                                }
                            }
                        } else {
                            Object valObject = mapValue.get(rootId);
                            if (valObject != null) {
                                if (kieu ==
                                    Utils.ENUM_KIEU_DU_LIEU.NUMBER.getId() ||
                                    kieu ==
                                    Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId() ||
                                    kieu ==
                                    Utils.ENUM_KIEU_DU_LIEU.DATE.getId() ||
                                    kieu ==
                                    Utils.ENUM_KIEU_DU_LIEU.LOAI_CHUNG_KHOAN.getId() ||
                                    kieu ==
                                    Utils.ENUM_KIEU_DU_LIEU.SAN_GIAO_DICH.getId()) {
                                    RichPanelLabelAndMessage label =
                                        new RichPanelLabelAndMessage();
                                    label.setLabel(ten);
                                    RichOutputText outputText =
                                        new RichOutputText();
                                    outputText.setValue(valObject);
                                    if (kieu ==
                                        Utils.ENUM_KIEU_DU_LIEU.DATE.getId()) {
                                        DateTimeConverter converter =
                                            (DateTimeConverter)FacesContext.getCurrentInstance().getApplication().createConverter("javax.faces.DateTime");
                                        converter.setLocale(new Locale(langCode));
                                        converter.setTimeZone(TimeZone.getTimeZone("GMT+7:00"));
                                        converter.setType("date");
                                        converter.setDateStyle("short");
                                        outputText.setConverter(converter);
                                    }
                                    label.getChildren().add(outputText);
                                    chiTietPanel.getChildren().add(label);
                                }
                                if (kieu ==
                                    Utils.ENUM_KIEU_DU_LIEU.CLOB.getId()) {
                                    RichPanelLabelAndMessage label =
                                        new RichPanelLabelAndMessage();
                                    label.setLabel(ten);
                                    RichOutputText outputFormatted =
                                        new RichOutputText();
                                    outputFormatted.setEscape(false);
                                    outputFormatted.setValue(valObject);
                                    label.getChildren().add(outputFormatted);
                                    chiTietPanel.getChildren().add(label);
                                }
                                if (kieu ==
                                    Utils.ENUM_KIEU_DU_LIEU.LINK.getId()) {
                                    RichPanelLabelAndMessage label =
                                        new RichPanelLabelAndMessage();
                                    label.setLabel(ten);
                                    RichGoLink goLink = new RichGoLink();
                                    goLink.setTargetFrame("_parent");
                                    goLink.setInlineStyle("padding:5px 7px;");
                                    goLink.setText((String)valObject);
                                    String link = (String)valObject;
                                    if (link != null) {
                                        link = link.toLowerCase();
                                        if (link.startsWith("http://") ==
                                            false) {
                                            link = "http://" + link;
                                        }
                                        goLink.setDestination(link);
                                    }
                                    label.getChildren().add(goLink);
                                    chiTietPanel.getChildren().add(label);
                                }
                                if (kieu ==
                                    Utils.ENUM_KIEU_DU_LIEU.EMAIL.getId()) {
                                    RichPanelLabelAndMessage label =
                                        new RichPanelLabelAndMessage();
                                    label.setLabel(ten);
                                    RichGoLink goLink = new RichGoLink();
                                    goLink.setTargetFrame("_parent");
                                    goLink.setInlineStyle("padding:5px 7px;");
                                    goLink.setText((String)valObject);
                                    goLink.setDestination("mailto:" +
                                                          valObject);
                                    label.getChildren().add(goLink);
                                    chiTietPanel.getChildren().add(label);
                                }
                                if (kieu ==
                                    Utils.ENUM_KIEU_DU_LIEU.FILE.getId()) {
                                    String htFileServletUrl =
                                        (String)request.getPortletSession().getAttribute("htfileservleturl");
                                    Row row = (Row)valObject;
                                    RichPanelLabelAndMessage label =
                                        new RichPanelLabelAndMessage();
                                    label.setLabel(ten);
                                    RichGoLink goLink = new RichGoLink();
                                    goLink.setTargetFrame("_parent");
                                    goLink.setInlineStyle("padding:5px 7px;");
                                    goLink.setText((String)row.getAttribute("TenFile"));
                                    goLink.setDestination(htFileServletUrl +
                                                          "?id=" +
                                                          row.getAttribute("Id"));
                                    label.getChildren().add(goLink);
                                    chiTietPanel.getChildren().add(label);
                                }
                                if (kieu ==
                                    Utils.ENUM_KIEU_DU_LIEU.LOGO.getId()) {
                                    String htFileServletUrl=
                                    (String)request.getPortletSession().getAttribute("htfileservleturl");
                                    Row row = (Row)valObject;
                                    RichPanelLabelAndMessage label =
                                        new RichPanelLabelAndMessage();
                                    label.setLabel(ten);
                                    RichImage image=new RichImage();
                                    image.setSource(htFileServletUrl+"?id=" +
                                                          row.getAttribute("Id"));
                                    label.getChildren().add(image);
                                    chiTietPanel.getChildren().add(label);
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    private HashMap<String, Object> getValueChiTiet(PortletRequest request) {
        HashMap<String, Object> mapValue = new HashMap();
        try {
            String donViRowKey =
                (String)request.getPortletSession().getAttribute("donviid");
            if (donViRowKey != null) {
                DCIteratorBinding donViView1Iterator =
                    Utils.getIteratorBinding("DlctDonViView1Iterator");
                if (donViView1Iterator.findRowByKeyString(donViRowKey) !=
                    null) {
                    donViView1Iterator.setCurrentRowWithKey(donViRowKey);
                    DCIteratorBinding gtDvTtView1Iterator =
                        Utils.getIteratorBinding("DlctGtDvTtView1Iterator");
                    gtDvTtView1Iterator.setRangeSize(-1);
                    Row[] rowsGtTt = gtDvTtView1Iterator.getAllRowsInRange();
                    if (rowsGtTt == null) {
                        rowsGtTt = new Row[] { };
                    }
                    for (int j = 0; j < rowsGtTt.length; j++) {
                        Row truongTtRow =
                            (Row)rowsGtTt[j].getAttribute("DlctTruongTtView");
                        if (truongTtRow != null) {
                            Number id = (Number)truongTtRow.getAttribute("Id");
                            Number kieuDuLieu =
                                (Number)truongTtRow.getAttribute("KieuDuLieu");
                            if (id != null && kieuDuLieu != null) {
                                int kieu = kieuDuLieu.intValue();
                                if (kieu ==
                                    Utils.ENUM_KIEU_DU_LIEU.NUMBER.getId()) {
                                    Number valNumber =
                                        (Number)rowsGtTt[j].getAttribute("ValNumber");
                                    if (valNumber != null) {
                                        mapValue.put(id.toString(),
                                                     valNumber.toString());
                                    }
                                }
                                if (kieu ==
                                    Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId()) {
                                    String valVarchar =
                                        (String)rowsGtTt[j].getAttribute("ValVarchar");
                                    if (valVarchar != null) {
                                        mapValue.put(id.toString(),
                                                     valVarchar);
                                    }
                                }
                                if (kieu ==
                                    Utils.ENUM_KIEU_DU_LIEU.LINK.getId()) {
                                    String valVarchar =
                                        (String)rowsGtTt[j].getAttribute("ValVarchar");
                                    if (valVarchar != null) {
                                        mapValue.put(id.toString(),
                                                     valVarchar);
                                    }
                                }
                                if (kieu ==
                                    Utils.ENUM_KIEU_DU_LIEU.EMAIL.getId()) {
                                    String valVarchar =
                                        (String)rowsGtTt[j].getAttribute("ValVarchar");
                                    if (valVarchar != null) {
                                        mapValue.put(id.toString(),
                                                     valVarchar);
                                    }
                                }
                                if (kieu ==
                                    Utils.ENUM_KIEU_DU_LIEU.DATE.getId()) {
                                    oracle.jbo.domain.Date valDate =
                                        (oracle.jbo.domain.Date)rowsGtTt[j].getAttribute("ValDate");
                                    if (valDate != null) {
                                        java.util.Date date =
                                            valDate.dateValue();
                                        if (date != null) {
                                            mapValue.put(id.toString(), date);
                                        }
                                    }
                                }
                                if (kieu ==
                                    Utils.ENUM_KIEU_DU_LIEU.CLOB.getId()) {
                                    ClobDomain valClob =
                                        (ClobDomain)rowsGtTt[j].getAttribute("ValClob");
                                    if (valClob != null) {
                                        mapValue.put(id.toString(),
                                                     valClob.toString());
                                    }
                                }
                                if (kieu ==
                                    Utils.ENUM_KIEU_DU_LIEU.FILE.getId()) {
                                    Row fileViewRow =
                                        (Row)rowsGtTt[j].getAttribute("HtFileView");
                                    if (fileViewRow != null) {
                                        mapValue.put(id.toString(),
                                                     fileViewRow);
                                    }
                                }
                                if (kieu ==
                                    Utils.ENUM_KIEU_DU_LIEU.LOGO.getId()) {
                                    Row fileViewRow =
                                        (Row)rowsGtTt[j].getAttribute("HtFileView");
                                    if (fileViewRow != null) {
                                        mapValue.put(id.toString(),
                                                     fileViewRow);
                                    }
                                }
                                if (kieu ==
                                    Utils.ENUM_KIEU_DU_LIEU.LOAI_CHUNG_KHOAN.getId()) {
                                    Row loaiChungKhoanRow =
                                        (Row)rowsGtTt[j].getAttribute("DlctLoaiChungKhoanView");
                                    if (loaiChungKhoanRow != null) {
                                        RowSet gtLckTtRowSet =
                                            (RowSet)loaiChungKhoanRow.getAttribute("DlctGtLckTtView");
                                        String ten = "";
                                        if (gtLckTtRowSet != null) {
                                            gtLckTtRowSet.setRangeSize(-1);
                                            Row[] gtLckTtRows =
                                                gtLckTtRowSet.getAllRowsInRange();
                                            if (gtLckTtRows == null) {
                                                gtLckTtRows = new Row[] { };
                                            }
                                            for (int k = 0;
                                                 k < gtLckTtRows.length; k++) {
                                                Row gtLckTtTruongTtRow =
                                                    (Row)gtLckTtRows[k].getAttribute("DlctTruongTtView");
                                                Number gtLckTtKieuDuLieu =
                                                    (Number)gtLckTtTruongTtRow.getAttribute("KieuDuLieu");
                                                Number gtLckTtViTriHienThi =
                                                    (Number)gtLckTtTruongTtRow.getAttribute("ViTriHienThi");
                                                if (gtLckTtViTriHienThi !=
                                                    null &&
                                                    gtLckTtKieuDuLieu !=
                                                    null) {
                                                    int gtLckviTri =
                                                        gtLckTtViTriHienThi.intValue();
                                                    int gtLckKieu =
                                                        gtLckTtKieuDuLieu.intValue();
                                                    if ((Utils.ENUM_VI_TRI_HIEN_THI.PORTLET_SELECT.getId() &
                                                         gtLckviTri) ==
                                                        Utils.ENUM_VI_TRI_HIEN_THI.PORTLET_SELECT.getId()) {
                                                        if (gtLckKieu ==
                                                            Utils.ENUM_KIEU_DU_LIEU.NUMBER.getId()) {
                                                            Number valNumber =
                                                                (Number)gtLckTtRows[k].getAttribute("ValNumber");
                                                            if (valNumber !=
                                                                null) {
                                                                ten =
ten + valNumber.toString() + " ";
                                                            }
                                                        }
                                                        if (gtLckKieu ==
                                                            Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId()) {
                                                            String valVarchar =
                                                                (String)gtLckTtRows[k].getAttribute("ValVarchar");
                                                            if (valVarchar !=
                                                                null) {
                                                                ten =
ten + valVarchar + " ";
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        mapValue.put(id.toString(), ten);
                                    }
                                }
                                if (kieu ==
                                    Utils.ENUM_KIEU_DU_LIEU.SAN_GIAO_DICH.getId()) {
                                    Row sanGiaoDichRow =
                                        (Row)rowsGtTt[j].getAttribute("DlctSanGiaoDichView");
                                    if (sanGiaoDichRow != null) {
                                        RowSet gtSgdTtRowSet =
                                            (RowSet)sanGiaoDichRow.getAttribute("DlctGtSgdTtView");
                                        String ten = "";
                                        if (gtSgdTtRowSet != null) {
                                            gtSgdTtRowSet.setRangeSize(-1);
                                            Row[] gtSgdTtRows =
                                                gtSgdTtRowSet.getAllRowsInRange();
                                            if (gtSgdTtRows == null) {
                                                gtSgdTtRows = new Row[] { };
                                            }
                                            for (int k = 0;
                                                 k < gtSgdTtRows.length; k++) {
                                                Row gtLckTtTruongTtRow =
                                                    (Row)gtSgdTtRows[k].getAttribute("DlctTruongTtView");
                                                Number gtLckTtKieuDuLieu =
                                                    (Number)gtLckTtTruongTtRow.getAttribute("KieuDuLieu");
                                                Number gtLckTtViTriHienThi =
                                                    (Number)gtLckTtTruongTtRow.getAttribute("ViTriHienThi");
                                                if (gtLckTtViTriHienThi !=
                                                    null &&
                                                    gtLckTtKieuDuLieu !=
                                                    null) {
                                                    int gtLckviTri =
                                                        gtLckTtViTriHienThi.intValue();
                                                    int gtLckKieu =
                                                        gtLckTtKieuDuLieu.intValue();
                                                    if ((Utils.ENUM_VI_TRI_HIEN_THI.PORTLET_SELECT.getId() &
                                                         gtLckviTri) ==
                                                        Utils.ENUM_VI_TRI_HIEN_THI.PORTLET_SELECT.getId()) {
                                                        if (gtLckKieu ==
                                                            Utils.ENUM_KIEU_DU_LIEU.NUMBER.getId()) {
                                                            Number valNumber =
                                                                (Number)gtSgdTtRows[k].getAttribute("ValNumber");
                                                            if (valNumber !=
                                                                null) {
                                                                ten =
ten + valNumber.toString() + " ";
                                                            }
                                                        }
                                                        if (gtLckKieu ==
                                                            Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId()) {
                                                            String valVarchar =
                                                                (String)gtSgdTtRows[k].getAttribute("ValVarchar");
                                                            if (valVarchar !=
                                                                null) {
                                                                ten =
ten + valVarchar + " ";
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        mapValue.put(id.toString(), ten);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            mapValue = null;
        }
        return mapValue;
    }

    private void resetIteratorChiTiet(PortletRequest request) {
        String loaiDonViId =
            (String)request.getPortletSession().getAttribute("loaidonviid");
        String langCode =
            (String)request.getPortletSession().getAttribute("langcode");
        if (langCode == null) {
            langCode = DEFAULT_LANGCODE;
        }

        List<AdvancedSearchGroup> listASG = new ArrayList();
        AdvancedSearchGroup asgTrangThai = new AdvancedSearchGroup();
        listASG.add(asgTrangThai);
        AdvancedSearchItem asiTrangThai = new AdvancedSearchItem();
        asgTrangThai.getListChildren().add(asiTrangThai);
        asiTrangThai.setItemName("TrangThai");
        asiTrangThai.setRequired(true);
        asiTrangThai.getListValue().add(0,
                                        new Number(Utils.ENUM_TRANG_THAI.CONG_BO.getId()));
        if (loaiDonViId != null) {
            try {
                Number loaiDonViNumber = new Number(loaiDonViId);
                AdvancedSearchGroup asg = new AdvancedSearchGroup();
                listASG.add(asg);
                AdvancedSearchItem asi = new AdvancedSearchItem();
                asg.getListChildren().add(asi);
                asi.setItemName("DlctDvLdvView");
                asi.setRequired(true);
                asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                AdvancedSearchGroup asgChild = new AdvancedSearchGroup();
                asi.getListChildren().add(asgChild);
                AdvancedSearchItem asiChild = new AdvancedSearchItem();
                asgChild.getListChildren().add(asiChild);
                asiChild.setItemName("DlctLoaiDonViId");
                asiChild.setRequired(true);
                asiChild.getListValue().add(loaiDonViNumber);
            } catch (Exception e) {
            }
        }
        if (langCode != null) {
            try {
                AdvancedSearchGroup asg = new AdvancedSearchGroup();
                listASG.add(asg);
                AdvancedSearchItem asi = new AdvancedSearchItem();
                asg.getListChildren().add(asi);
                asi.setItemName("DlctDvNnView");
                asi.setRequired(true);
                asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                AdvancedSearchGroup asgChild = new AdvancedSearchGroup();
                asi.getListChildren().add(asgChild);
                AdvancedSearchItem asiChild = new AdvancedSearchItem();
                asgChild.getListChildren().add(asiChild);
                asiChild.setItemName("DlctNgonNguView");
                asiChild.setRequired(true);
                asiChild.setOperator(AdvancedSearchItem.OPER_EXISTS);
                AdvancedSearchGroup asgChild2 = new AdvancedSearchGroup();
                asiChild.getListChildren().add(asgChild2);
                AdvancedSearchItem asiChild2 = new AdvancedSearchItem();
                asgChild2.getListChildren().add(asiChild2);
                asiChild2.setItemName("Ma");
                asiChild2.setRequired(true);
                asiChild2.getListValue().add(langCode);
            } catch (Exception e) {
            }
        }
        Utils.searchadvanced("DlctDonViView1Iterator", listASG);

        listASG = new ArrayList();
        asgTrangThai = new AdvancedSearchGroup();
        listASG.add(asgTrangThai);
        asiTrangThai = new AdvancedSearchItem();
        asgTrangThai.getListChildren().add(asiTrangThai);
        asiTrangThai.setItemName("TrangThai");
        asiTrangThai.setRequired(true);
        asiTrangThai.getListValue().add(0,
                                        new Number(Utils.ENUM_TRANG_THAI.CONG_BO.getId()));
        AdvancedSearchGroup asgLoaiTruongTt = new AdvancedSearchGroup();
        listASG.add(asgLoaiTruongTt);
        AdvancedSearchItem asiLoaiTruongTt = new AdvancedSearchItem();
        asgLoaiTruongTt.getListChildren().add(asiLoaiTruongTt);
        asiLoaiTruongTt.setItemName("DlctLoaiTruongTt");
        asiLoaiTruongTt.setRequired(true);
        asiLoaiTruongTt.getListValue().add(0,
                                           new Number(Utils.ENUM_LOAI_TRUONG_TT.DON_VI.getId()));
        if (loaiDonViId != null) {
            try {
                Number loaiDonViNumber = new Number(loaiDonViId);
                AdvancedSearchGroup asg = new AdvancedSearchGroup();
                listASG.add(asg);
                AdvancedSearchItem asi = new AdvancedSearchItem();
                asg.getListChildren().add(asi);
                asi.setItemName("DlctLdvTtView");
                asi.setRequired(true);
                asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                AdvancedSearchGroup asgChild = new AdvancedSearchGroup();
                asi.getListChildren().add(asgChild);
                AdvancedSearchItem asiChild = new AdvancedSearchItem();
                asgChild.getListChildren().add(asiChild);
                asiChild.setItemName("DlctLoaiDonViId");
                asiChild.setRequired(true);
                asiChild.getListValue().add(loaiDonViNumber);
            } catch (Exception e) {
            }
        }
        if (langCode != null) {
            try {
                AdvancedSearchGroup asg = new AdvancedSearchGroup();
                listASG.add(asg);
                AdvancedSearchItem asi = new AdvancedSearchItem();
                asg.getListChildren().add(asi);
                asi.setItemName("DlctNgonNguView");
                asi.setRequired(true);
                asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                AdvancedSearchGroup asgChild = new AdvancedSearchGroup();
                asi.getListChildren().add(asgChild);
                AdvancedSearchItem asiChild = new AdvancedSearchItem();
                asgChild.getListChildren().add(asiChild);
                asiChild.setItemName("Ma");
                asiChild.setRequired(true);
                asiChild.getListValue().add(langCode);
            } catch (Exception e) {
            }
        }
        Utils.searchadvanced("DlctTruongTtView1Iterator", listASG);
    }

    private void createFormBaoCao(PortletRequest request, int pageNum) {
        searchBaoCaoPanel.getChildren().clear();
        tableBaoCao.getChildren().clear();
        List listValue = new ArrayList();
        try {
            String langCode =
                (String)request.getPortletSession().getAttribute("langcode");
            if (langCode == null) {
                langCode = DEFAULT_LANGCODE;
            }

            String donViRowKey =
                (String)request.getPortletSession().getAttribute("donviid");
            if (donViRowKey != null) {
                DCIteratorBinding donViView1Iterator =
                    Utils.getIteratorBinding("DlctDonViView1Iterator");
                if (donViView1Iterator.findRowByKeyString(donViRowKey) !=
                    null) {
                    donViView1Iterator.setCurrentRowWithKey(donViRowKey);
                    resetPagingBaoCao(request, "DlctCbttView2Iterator",
                                      pageNum);
                    String htFileServletUrl =
                        (String)request.getPortletSession().getAttribute("htfileservleturl");
                    {
                        String yearSearch =
                            (String)request.getPortletSession().getAttribute("year");

                        FacesContext fc = FacesContext.getCurrentInstance();
                        Application app = fc.getApplication();
                        ExpressionFactory elFactory =
                            app.getExpressionFactory();
                        ELContext elContext = fc.getELContext();
                        MethodExpression methodExpression =
                            elFactory.createMethodExpression(elContext,
                                                             "#{tongHop.changeNamBaoCao}",
                                                             null,
                                                             new Class[] { ValueChangeEvent.class });
                        MethodExpressionMethodBinding methodExpressionMethodBinding =
                            new MethodExpressionMethodBinding(methodExpression);

                        RichSelectOneChoice selectOneChoiceYear =
                            new RichSelectOneChoice();
                        selectOneChoiceYear.getAttributes().put("valueChangeListener",
                                                                methodExpressionMethodBinding);
                        selectOneChoiceYear.setId(SEARCH_NAM);
                        Calendar calendar = Calendar.getInstance();
                        int year = calendar.get(Calendar.YEAR);
                        List<SelectItem> listSelectItem = new ArrayList();
                        for (int i = year; i >= 2005; i--) {
                            SelectItem si = new SelectItem();
                            si.setValue("" + i);
                            si.setLabel(String.valueOf(i));
                            listSelectItem.add(si);
                        }
                        UISelectItems uiSelectItems = new UISelectItems();
                        uiSelectItems.setValue(listSelectItem);
                        selectOneChoiceYear.setLabel(getResource("NAM"));
                        selectOneChoiceYear.setValue(yearSearch);
                        selectOneChoiceYear.setAutoSubmit(true);
                        selectOneChoiceYear.setUnselectedLabel(getResource("TAT_CA"));
                        selectOneChoiceYear.getChildren().add(uiSelectItems);
                        searchBaoCaoPanel.getChildren().add(selectOneChoiceYear);
                    }
                    FacesContext fc = FacesContext.getCurrentInstance();
                    Application app = fc.getApplication();
                    ExpressionFactory elFactory = app.getExpressionFactory();
                    ELContext elContext = fc.getELContext();
                    ValueExpression valueExp;
                    RichColumn column = new RichColumn();
                    column.setSeparateRows(true);
                    column.setAlign(RichColumn.ALIGN_CENTER);
                    column.setHeaderText("STT");
                    column.setSortable(false);
                    column.setNoWrap(false);
                    column.setWidth("15");
                    RichOutputText outputText = new RichOutputText();
                    valueExp =
                            elFactory.createValueExpression(elContext, "#{row['STT']}",
                                                            Object.class);
                    outputText.setValueExpression("value", valueExp);
                    column.getChildren().add(outputText);
                    tableBaoCao.getChildren().add(column);
                    DCIteratorBinding truongTtView1Iterator =
                        Utils.getIteratorBinding("DlctTruongTtView1Iterator");
                    truongTtView1Iterator.setRangeSize(-1);
                    Row[] rows = truongTtView1Iterator.getAllRowsInRange();
                    if (rows == null) {
                        rows = new Row[] { };
                    }

                    RichPanelBorderLayout panelDownload =
                        new RichPanelBorderLayout();
                    for (int i = 0; i < rows.length; i++) {
                        String ten = (String)rows[i].getAttribute("TenTruong");
                        Number kieuDuLieu =
                            (Number)rows[i].getAttribute("KieuDuLieu");
                        Number viTriHienThi =
                            (Number)rows[i].getAttribute("ViTriHienThi");
            String tablePortletColumnAlign = (String)rows[i].getAttribute("TablePortletColumnAlign");
            String tablePortletColumnWidth = (String)rows[i].getAttribute("TablePortletColumnWidth");
                        Row loopRow = rows[i];
                        Row rootRow = null;
                        while (loopRow != null) {
                            rootRow = loopRow;
                            loopRow =
                                    (Row)loopRow.getAttribute("DlctTruongTtTuIdDlctTruongTtView");
                        }
                        String rootId =
                            ((Number)rootRow.getAttribute("Id")).toString();
                        if (viTriHienThi != null && kieuDuLieu != null) {
                            int viTri = viTriHienThi.intValue();
                            int kieu = kieuDuLieu.intValue();
                            if ((Utils.ENUM_VI_TRI_HIEN_THI.PORTLET_TABLE.getId() &
                                 viTri) ==
                                Utils.ENUM_VI_TRI_HIEN_THI.PORTLET_TABLE.getId()) {
                                if (kieu ==
                                    Utils.ENUM_KIEU_DU_LIEU.IN_OUT_KIEM_TOAN_VIEN.getId() ||
                                    kieu ==
                                    Utils.ENUM_KIEU_DU_LIEU.KIEM_TOAN_VIEN.getId() ||
                                    kieu ==
                                    Utils.ENUM_KIEU_DU_LIEU.SL_KIEM_TOAN_VIEN.getId()) {
                                    // khong dua ra giao dien bang
                                } else {
                                    if (kieu ==
                                        Utils.ENUM_KIEU_DU_LIEU.FILE.getId()) {
                                        RichGoLink goLink = new RichGoLink();
                                        goLink.setTargetFrame("_parent");
                                        valueExp =
                                                elFactory.createValueExpression(elContext,
                                                                                "#{row['" +
                                                                                rootId +
                                                                                LINK_DES +
                                                                                "']}",
                                                                                Object.class);
                                        goLink.setValueExpression("destination",
                                                                  valueExp);
                                        valueExp =
                                                elFactory.createValueExpression(elContext,
                                                                                "#{row['" +
                                                                                rootId +
                                                                                "'] != null and row['" +
                                                                                rootId +
                                                                                "'] != '' }",
                                                                                Object.class);
                                        goLink.setValueExpression("rendered(",
                                                                  valueExp);
                                        valueExp =
                                                elFactory.createValueExpression(elContext,
                                                                                "#{row['" +
                                                                                rootId +
                                                                                "']}",
                                                                                Object.class);
                                        goLink.setValueExpression("text",
                                                                  valueExp);
                                        panelDownload.getChildren().add(goLink);
                                    } else if (kieu ==
                                               Utils.ENUM_KIEU_DU_LIEU.LINK.getId()) {
                                        column = new RichColumn();
                                        column.setHeaderText(ten);
                                        column.setNoWrap(false);
                                        if(tablePortletColumnAlign!=null&&tablePortletColumnAlign.isEmpty()==false){
                                            column.setAlign(tablePortletColumnAlign);
                                        }
                                        if(tablePortletColumnWidth!=null&&tablePortletColumnWidth.isEmpty()==false){
                                           column.setWidth(tablePortletColumnWidth);
                                        }else{
                                            column.setWidth("50");
                                        }
                                        RichGoLink goLink = new RichGoLink();
                                        goLink.setTargetFrame("_parent");
                                        valueExp =
                                                elFactory.createValueExpression(elContext,
                                                                                "#{row['" +
                                                                                rootId +
                                                                                LINK_DES +
                                                                                "']}",
                                                                                Object.class);
                                        goLink.setValueExpression("destination",
                                                                  valueExp);
                                        valueExp =
                                                elFactory.createValueExpression(elContext,
                                                                                "#{row['" +
                                                                                rootId +
                                                                                "']}",
                                                                                Object.class);
                                        goLink.setValueExpression("text",
                                                                  valueExp);
                                        column.getChildren().add(goLink);
                                        tableBaoCao.getChildren().add(column);
                                    } else if (kieu ==
                                               Utils.ENUM_KIEU_DU_LIEU.EMAIL.getId()) {
                                        column = new RichColumn();
                                        column.setHeaderText(ten);
                                        column.setNoWrap(false);
                                        if(tablePortletColumnAlign!=null&&tablePortletColumnAlign.isEmpty()==false){
                                            column.setAlign(tablePortletColumnAlign);
                                        }
                                        if(tablePortletColumnWidth!=null&&tablePortletColumnWidth.isEmpty()==false){
                                           column.setWidth(tablePortletColumnWidth);
                                        }else{
                                            column.setWidth("50");
                                        }
                                        RichGoLink goLink = new RichGoLink();
                                        goLink.setTargetFrame("_parent");
                                        valueExp =
                                                elFactory.createValueExpression(elContext,
                                                                                "#{row['" +
                                                                                rootId +
                                                                                LINK_DES +
                                                                                "']}",
                                                                                Object.class);
                                        goLink.setValueExpression("destination",
                                                                  valueExp);
                                        valueExp =
                                                elFactory.createValueExpression(elContext,
                                                                                "#{row['" +
                                                                                rootId +
                                                                                "']}",
                                                                                Object.class);
                                        goLink.setValueExpression("text",
                                                                  valueExp);
                                        column.getChildren().add(goLink);
                                        tableBaoCao.getChildren().add(column);
                                    } else {
                                        column = new RichColumn();
                                        column.setHeaderText(ten);
                                        //column.setRowHeader("unstyled");
                                        column.setSortable(false);
                                        column.setNoWrap(false);
                                        if(tablePortletColumnAlign!=null&&tablePortletColumnAlign.isEmpty()==false){
                                            column.setAlign(tablePortletColumnAlign);
                                        }
                                        if(tablePortletColumnWidth!=null&&tablePortletColumnWidth.isEmpty()==false){
                                           column.setWidth(tablePortletColumnWidth);
                                        }else{
                                            column.setWidth("50");
                                        }
                                        outputText = new RichOutputText();
                                        if (kieu ==
                                            Utils.ENUM_KIEU_DU_LIEU.DATE.getId()) {
                                            DateTimeConverter converter =
                                                (DateTimeConverter)FacesContext.getCurrentInstance().getApplication().createConverter("javax.faces.DateTime");
                                            converter.setLocale(new Locale(langCode));
                                            converter.setTimeZone(TimeZone.getTimeZone("GMT+7:00"));
                                            converter.setType("date");
                                            converter.setDateStyle("short");
                                            outputText.setConverter(converter);
                                        }
                                        valueExp =
                                                elFactory.createValueExpression(elContext,
                                                                                "#{row['" +
                                                                                rootId +
                                                                                "']}",
                                                                                Object.class);
                                        outputText.setValueExpression("value",
                                                                      valueExp);
                                        column.getChildren().add(outputText);
                                        tableBaoCao.getChildren().add(column);
                                    }
                                }
                            }
                        }
                    }
                    {

                        column = new RichColumn();
                        column.setWidth("10");
                        column.setHeaderText(getResource("KY_BAO_CAO"));
                        column.setAlign(RichColumn.ALIGN_CENTER);
                        column.setSortable(false);
                        column.setNoWrap(false);
                        outputText = new RichOutputText();
                        valueExp =
                                elFactory.createValueExpression(elContext, "#{row['ten']}",
                                                                Object.class);
                        outputText.setValueExpression("value", valueExp);
                        column.getChildren().add(outputText);
                        tableBaoCao.getChildren().add(column);

                        column = new RichColumn();
                        column.setWidth("5");
                        column.setHeaderText(getResource("NAM"));
                        column.setAlign(RichColumn.ALIGN_CENTER);
                        column.setSortable(false);
                        column.setNoWrap(false);
                        outputText = new RichOutputText();
                        valueExp =
                                elFactory.createValueExpression(elContext, "#{row['nam']}",
                                                                Object.class);
                        outputText.setValueExpression("value", valueExp);
                        column.getChildren().add(outputText);
                        tableBaoCao.getChildren().add(column);

                    }
                    if (panelDownload.getChildren().size() > 0) {
                        column = new RichColumn();
                        column.setWidth("15");
                        column.setSeparateRows(true);
                        column.setAlign(RichColumn.ALIGN_CENTER);
                        column.setHeaderText("Tải file");
                        column.setSortable(false);
                        column.setNoWrap(false);
                        column.getChildren().add(panelDownload);
                        tableBaoCao.getChildren().add(column);
                    }


                    DCIteratorBinding cbttView2Iterator =
                        Utils.getIteratorBinding("DlctCbttView2Iterator");
                    {
                        String currentRowKey = "";
                        if (cbttView2Iterator.getCurrentRow() != null &&
                            cbttView2Iterator.getCurrentRowIndexInRange() >=
                            0 &&
                            cbttView2Iterator.getCurrentRowIndexInRange() <
                            cbttView2Iterator.getRangeSize()) {
                            currentRowKey =
                                    cbttView2Iterator.getCurrentRow().getKey().toStringFormat(false);
                        }
                        RowKeySet rowKeySet = tableBaoCao.getSelectedRowKeys();
                        if (rowKeySet == null) {
                            rowKeySet = new RowKeySetImpl();
                            tableBaoCao.setSelectedRowKeys(rowKeySet);
                        }
                        rowKeySet.removeAll();
                        rows = cbttView2Iterator.getAllRowsInRange();
                        if (rows == null) {
                            rows = new Row[] { };
                        }
                        for (int i = 0; i < rows.length; i++) {
                            cbttView2Iterator.setCurrentRowIndexInRange(i);
                            String rowKey =
                                cbttView2Iterator.getCurrentRow().getKey().toStringFormat(false);
                            if (currentRowKey == null ||
                                currentRowKey.isEmpty()) {
                                currentRowKey = rowKey;
                            }
                            if (currentRowKey.equals(rowKey)) {
                                rowKeySet.add(i);
                            }
                            HashMap<String, Object> mapValue = new HashMap();
                            mapValue.put("STT",
                                         cbttView2Iterator.getRangeStart() +
                                         i + 1);
                            mapValue.put(ROW_KEY, rowKey);

                            mapValue.put("nam",
                                         cbttView2Iterator.getCurrentRow().getAttribute("Nam"));

                            Row rowLoaiCbtt =
                                (Row)cbttView2Iterator.getCurrentRow().getAttribute("DlctLoaiCbttView");
                            if (rowLoaiCbtt != null) {
                                mapValue.put("ten",
                                             rowLoaiCbtt.getAttribute("Ten"));
                            }


                            RowSet rowSetGtTt =
                                (RowSet)cbttView2Iterator.getCurrentRow().getAttribute("DlctGtCbttTtView");
                            rowSetGtTt.setRangeSize(-1);
                            Row[] rowsGtTt = rowSetGtTt.getAllRowsInRange();
                            if (rowsGtTt == null) {
                                rowsGtTt = new Row[] { };
                            }
                            for (int j = 0; j < rowsGtTt.length; j++) {
                                Row truongTtRow =
                                    (Row)rowsGtTt[j].getAttribute("DlctTruongTtView");
                                if (truongTtRow != null) {
                                    Number id =
                                        (Number)truongTtRow.getAttribute("Id");
                                    Number kieuDuLieu =
                                        (Number)truongTtRow.getAttribute("KieuDuLieu");
                                    if (id != null && kieuDuLieu != null) {
                                        int kieu = kieuDuLieu.intValue();
                                        if (kieu ==
                                            Utils.ENUM_KIEU_DU_LIEU.NUMBER.getId()) {
                                            Number valNumber =
                                                (Number)rowsGtTt[j].getAttribute("ValNumber");
                                            if (valNumber != null) {
                                                mapValue.put(id.toString(),
                                                             valNumber.toString());
                                            }
                                        }
                                        if (kieu ==
                                            Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId()) {
                                            String valVarchar =
                                                (String)rowsGtTt[j].getAttribute("ValVarchar");
                                            if (valVarchar != null) {
                                                mapValue.put(id.toString(),
                                                             valVarchar);
                                            }
                                        }
                                        if (kieu ==
                                            Utils.ENUM_KIEU_DU_LIEU.LINK.getId()) {
                                            String valVarchar =
                                                (String)rowsGtTt[j].getAttribute("ValVarchar");
                                            if (valVarchar != null) {
                                                String link =
                                                    valVarchar.toLowerCase();
                                                if (link.startsWith("http://") ==
                                                    false) {
                                                    link = "http://" + link;
                                                }
                                                mapValue.put(id.toString() +
                                                             LINK_DES, link);
                                                mapValue.put(id.toString(),
                                                             valVarchar);
                                            }
                                        }
                                        if (kieu ==
                                            Utils.ENUM_KIEU_DU_LIEU.EMAIL.getId()) {
                                            String valVarchar =
                                                (String)rowsGtTt[j].getAttribute("ValVarchar");
                                            if (valVarchar != null) {
                                                String link =
                                                    "mailto:" + valVarchar.toLowerCase();
                                                mapValue.put(id.toString() +
                                                             LINK_DES, link);
                                                mapValue.put(id.toString(),
                                                             valVarchar);
                                            }
                                        }
                                        if (kieu ==
                                            Utils.ENUM_KIEU_DU_LIEU.DATE.getId()) {
                                            oracle.jbo.domain.Date valDate =
                                                (oracle.jbo.domain.Date)rowsGtTt[j].getAttribute("ValDate");
                                            if (valDate != null) {
                                                java.util.Date date =
                                                    valDate.dateValue();
                                                if (date != null) {
                                                    mapValue.put(id.toString(),
                                                                 date);
                                                }
                                            }
                                        }
                                        if (kieu ==
                                            Utils.ENUM_KIEU_DU_LIEU.CLOB.getId()) {
                                            ClobDomain valClob =
                                                (ClobDomain)rowsGtTt[j].getAttribute("ValClob");
                                            if (valClob != null) {
                                                mapValue.put(id.toString(),
                                                             valClob.toString());
                                            }
                                        }
                                        if (kieu ==
                                            Utils.ENUM_KIEU_DU_LIEU.FILE.getId()) {
                                            Row fileViewRow =
                                                (Row)rowsGtTt[j].getAttribute("HtFileView");
                                            if (fileViewRow != null) {
                                                String tenFile =
                                                    (String)fileViewRow.getAttribute("TenFile");
                                                if (tenFile != null) {
                                                    mapValue.put(id.toString(),
                                                                 getResource("DOWNLOAD"));
                                                    mapValue.put(id.toString() +
                                                                 LINK_DES,
                                                                 htFileServletUrl +
                                                                 "?id=" +
                                                                 fileViewRow.getAttribute("Id"));
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            listValue.add(mapValue);
                        }
                        if (currentRowKey != null &&
                            currentRowKey.isEmpty() == false) {
                            cbttView2Iterator.setCurrentRowWithKey(currentRowKey);
                        }
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        tableBaoCao.setValue(listValue);
        AdfFacesContext.getCurrentInstance().addPartialTarget(tableBaoCao);
    }

    private void resetPagingBaoCao(PortletRequest request, String iteratorName,
                                   int pageNum) {
        FacesContext fc = FacesContext.getCurrentInstance();
        Application app = fc.getApplication();
        ExpressionFactory elFactory = app.getExpressionFactory();
        ELContext elContext = fc.getELContext();
        pagingBaoCaoPanel.getChildren().clear();
        DCIteratorBinding iterator = Utils.getIteratorBinding(iteratorName);
        int rowCount = (int)iterator.getEstimatedRowCount();
        int pageSize =
            DEFAULT_SIZE; //Utils.getPageSize("HtCauHinhView1Iterator");
        try {
            pageSize =
                    Integer.parseInt((String)request.getPortletSession().getAttribute("soluongbanghi"));
        } catch (Exception e) {

        }
        int pageCount = 1;
        if (rowCount > pageSize) {
            if (rowCount % pageSize == 0) {
                pageCount = rowCount / pageSize;
            } else {
                pageCount = rowCount / pageSize + 1;
            }
        }

        if (pageNum < 1) {
            pageNum = 1;
        }
        if (pageNum > pageCount) {
            pageNum = pageCount;
        }
        int first = 1;
        if (pageNum < 3) {
            first = 1;
        } else if (pageNum + 5 > pageCount) {
            if (pageNum + 2 > pageCount) {
                if (pageCount - 4 < 1)
                    first = 1;
                else {
                    first = pageCount - 4;
                }
            } else {
                if (pageCount < 6) {
                    first = 1;
                } else {
                    first = pageNum - 2;
                }
            }
        } else {
            first = pageNum - 2;
        }

        MethodExpression methodExpression =
            elFactory.createMethodExpression(elContext,
                                             "#{tongHop.changePageBaoCao}",
                                             null,
                                             new Class[] { ActionEvent.class });
        MethodExpressionMethodBinding methodExpressionMethodBinding =
            new MethodExpressionMethodBinding(methodExpression);
        RichCommandLink commandLink = new RichCommandLink();
        commandLink.setPartialSubmit(true);
        commandLink.setText(getResource("PREV"));
        commandLink.getAttributes().put("actionListener",
                                        methodExpressionMethodBinding);
        commandLink.getAttributes().put("pageNum", pageNum - 1);
        commandLink.setInlineStyle("display:block;width:60px;text-align:center;padding-right:3px;");
        pagingBaoCaoPanel.getChildren().add(commandLink);
        if (pageNum == 1) {
            commandLink.setDisabled(true);
        } else {
            commandLink.setDisabled(false);
        }
        if(pageNum>3){
        methodExpression =
            elFactory.createMethodExpression(elContext, "#{tongHop.changePageBaoCao}",
                                             null,
                                             new Class[] { ActionEvent.class });
        methodExpressionMethodBinding =
            new MethodExpressionMethodBinding(methodExpression);
            RichCommandLink commandLinkFirst = new RichCommandLink();
            commandLinkFirst.setPartialSubmit(true);
            commandLinkFirst.setText("" +1);
            commandLinkFirst.getAttributes().put("actionListener",
                                            methodExpressionMethodBinding);
            commandLinkFirst.getAttributes().put("pageNum", 1);
                commandLink.setInlineStyle("display:block;padding-right:3px;font-weight:bold;");
            pagingBaoCaoPanel.getChildren().add(commandLinkFirst);
            RichOutputText outputText=new RichOutputText();
            outputText.setValue("...");
            pagingBaoCaoPanel.getChildren().add(outputText);
        }
        for (int i = first, j = 0; i <= pageCount && j < 5; i++, j++) {
            methodExpression =
                    elFactory.createMethodExpression(elContext, "#{tongHop.changePageBaoCao}",
                                                     null,
                                                     new Class[] { ActionEvent.class });
            methodExpressionMethodBinding =
                    new MethodExpressionMethodBinding(methodExpression);
            commandLink = new RichCommandLink();
            commandLink.setPartialSubmit(true);
            if (i == pageNum) {
                commandLink.setDisabled(true);
                commandLink.setInlineStyle("display:block;padding-right:3px;font-weight:bold; color:#CCC;");
            } else {
                commandLink.setInlineStyle("display:block;padding-right:3px;font-weight:bold;");
            }
            if(i==pageCount){
            commandLink.setText("" + i+"["+rowCount+"]");
            }else{
                commandLink.setText("" + i);
            }
            commandLink.getAttributes().put("actionListener",
                                            methodExpressionMethodBinding);
            commandLink.getAttributes().put("pageNum", i);
            pagingBaoCaoPanel.getChildren().add(commandLink);
        }
        if (pageNum+2 < pageCount) {
        methodExpression =
                elFactory.createMethodExpression(elContext, "#{tongHop.changePageBaoCao}",
                                                 null,
                                                 new Class[] { ActionEvent.class });
        methodExpressionMethodBinding =
                new MethodExpressionMethodBinding(methodExpression);
            RichOutputText outputText=new RichOutputText();
            outputText.setValue("...");
        pagingBaoCaoPanel.getChildren().add(outputText);
            
            RichCommandLink commandLinkLast = new RichCommandLink();
            commandLinkLast.setPartialSubmit(true);
            commandLinkLast.setText("" + pageCount+"["+rowCount+"]");
            commandLinkLast.getAttributes().put("actionListener",
                                            methodExpressionMethodBinding);
            commandLinkLast.getAttributes().put("pageNum", pageCount);
            commandLinkLast.setInlineStyle("margin:0 2px;");
        pagingBaoCaoPanel.getChildren().add(commandLinkLast);
        }
        methodExpression =
                elFactory.createMethodExpression(elContext, "#{tongHop.changePageBaoCao}",
                                                 null,
                                                 new Class[] { ActionEvent.class });
        methodExpressionMethodBinding =
                new MethodExpressionMethodBinding(methodExpression);
        commandLink = new RichCommandLink();
        commandLink.setPartialSubmit(true);
        commandLink.setText(getResource("NEXT"));
        commandLink.getAttributes().put("actionListener",
                                        methodExpressionMethodBinding);
        commandLink.getAttributes().put("pageNum", pageNum + 1);
        commandLink.setInlineStyle("display:block;width:60px;text-align:center;padding-right:3px;");
        if (pageNum== pageCount) {
            commandLink.setDisabled(true);
        } else {
            commandLink.setDisabled(false);
        }
        pagingBaoCaoPanel.getChildren().add(commandLink);

        iterator.executeQuery();
        if ((pageNum) * pageSize > rowCount) {
            iterator.setRangeSize(rowCount - (pageNum - 1) * pageSize);
        } else {
            iterator.setRangeSize(pageSize);
        }
        iterator.setRangeStart((pageNum - 1) * pageSize);

        AdfFacesContext.getCurrentInstance().addPartialTarget(pagingBaoCaoPanel);
    }

    private void resetIteratorBaoCao(PortletRequest request) {
        String loaiDonViId =
            (String)request.getPortletSession().getAttribute("loaidonviid");
        String langCode =
            (String)request.getPortletSession().getAttribute("langcode");
        if (langCode == null) {
            langCode = DEFAULT_LANGCODE;
        }
        String yearSearch =
            (String)request.getPortletSession().getAttribute("year");
        {
            List<AdvancedSearchGroup> listASG = new ArrayList();
            AdvancedSearchGroup asgTrangThai = new AdvancedSearchGroup();
            listASG.add(asgTrangThai);
            AdvancedSearchItem asiTrangThai = new AdvancedSearchItem();
            asgTrangThai.getListChildren().add(asiTrangThai);
            asiTrangThai.setItemName("TrangThai");
            asiTrangThai.setRequired(true);
            asiTrangThai.getListValue().add(0,
                                            new Number(Utils.ENUM_TRANG_THAI.CONG_BO.getId()));
            if (loaiDonViId != null) {
                try {
                    Number loaiDonViNumber = new Number(loaiDonViId);
                    AdvancedSearchGroup asg = new AdvancedSearchGroup();
                    listASG.add(asg);
                    AdvancedSearchItem asi = new AdvancedSearchItem();
                    asg.getListChildren().add(asi);
                    asi.setItemName("DlctDvLdvView");
                    asi.setRequired(true);
                    asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                    AdvancedSearchGroup asgChild = new AdvancedSearchGroup();
                    asi.getListChildren().add(asgChild);
                    AdvancedSearchItem asiChild = new AdvancedSearchItem();
                    asgChild.getListChildren().add(asiChild);
                    asiChild.setItemName("DlctLoaiDonViId");
                    asiChild.setRequired(true);
                    asiChild.getListValue().add(loaiDonViNumber);
                } catch (Exception e) {
                }
            }
            if (langCode != null) {
                try {
                    AdvancedSearchGroup asg = new AdvancedSearchGroup();
                    listASG.add(asg);
                    AdvancedSearchItem asi = new AdvancedSearchItem();
                    asg.getListChildren().add(asi);
                    asi.setItemName("DlctDvNnView");
                    asi.setRequired(true);
                    asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                    AdvancedSearchGroup asgChild = new AdvancedSearchGroup();
                    asi.getListChildren().add(asgChild);
                    AdvancedSearchItem asiChild = new AdvancedSearchItem();
                    asgChild.getListChildren().add(asiChild);
                    asiChild.setItemName("DlctNgonNguView");
                    asiChild.setRequired(true);
                    asiChild.setOperator(AdvancedSearchItem.OPER_EXISTS);
                    AdvancedSearchGroup asgChild2 = new AdvancedSearchGroup();
                    asiChild.getListChildren().add(asgChild2);
                    AdvancedSearchItem asiChild2 = new AdvancedSearchItem();
                    asgChild2.getListChildren().add(asiChild2);
                    asiChild2.setItemName("Ma");
                    asiChild2.setRequired(true);
                    asiChild2.getListValue().add(langCode);
                } catch (Exception e) {
                }
            }
            Utils.searchadvanced("DlctDonViView1Iterator", listASG);
        }
        String donViRowKey =
            (String)request.getPortletSession().getAttribute("donviid");
        if (donViRowKey != null) {
            DCIteratorBinding donViView1Iterator =
                Utils.getIteratorBinding("DlctDonViView1Iterator");
            if (donViView1Iterator.findRowByKeyString(donViRowKey) != null) {
                donViView1Iterator.setCurrentRowWithKey(donViRowKey);
                List<AdvancedSearchGroup> listASG = new ArrayList();
                AdvancedSearchGroup asgTrangThai = new AdvancedSearchGroup();
                listASG.add(asgTrangThai);
                AdvancedSearchItem asiTrangThai = new AdvancedSearchItem();
                asgTrangThai.getListChildren().add(asiTrangThai);
                asiTrangThai.setItemName("TrangThai");
                asiTrangThai.setRequired(true);
                asiTrangThai.getListValue().add(0,
                                                new Number(Utils.ENUM_TRANG_THAI.CONG_BO.getId()));
                if (yearSearch != null && yearSearch.isEmpty() == false) {
                    AdvancedSearchGroup asg = new AdvancedSearchGroup();
                    listASG.add(asg);
                    AdvancedSearchItem asi = new AdvancedSearchItem();
                    asg.getListChildren().add(asi);
                    asi.setItemName("Nam");
                    asi.setRequired(true);
                    asi.getListValue().add(0, yearSearch);
                }
                try {
                    AdvancedSearchGroup asg = new AdvancedSearchGroup();
                    listASG.add(asg);
                    AdvancedSearchItem asi = new AdvancedSearchItem();
                    asg.getListChildren().add(asi);
                    asi.setItemName("DlctLoaiCbttView");
                    asi.setRequired(true);
                    asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                    AdvancedSearchGroup asgChild = new AdvancedSearchGroup();
                    asi.getListChildren().add(asgChild);
                    AdvancedSearchItem asiChild = new AdvancedSearchItem();
                    asgChild.getListChildren().add(asiChild);
                    asiChild.setItemName("BaoCao");
                    asiChild.setRequired(true);
                    asiChild.setOperator(AdvancedSearchItem.OPER_IN);
                    asiChild.getListValue().add(new Number(Utils.ENUM_BAO_CAO.BAO_CAO.getId()));
                } catch (Exception e) {
                }
                if (langCode != null) {
                    try {
                        AdvancedSearchGroup asg = new AdvancedSearchGroup();
                        listASG.add(asg);
                        AdvancedSearchItem asi = new AdvancedSearchItem();
                        asg.getListChildren().add(asi);
                        asi.setItemName("DlctCbttNnView");
                        asi.setRequired(true);
                        asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                        AdvancedSearchGroup asgChild =
                            new AdvancedSearchGroup();
                        asi.getListChildren().add(asgChild);
                        AdvancedSearchItem asiChild = new AdvancedSearchItem();
                        asgChild.getListChildren().add(asiChild);
                        asiChild.setItemName("DlctNgonNguView");
                        asiChild.setRequired(true);
                        asiChild.setOperator(AdvancedSearchItem.OPER_EXISTS);
                        AdvancedSearchGroup asgChild2 =
                            new AdvancedSearchGroup();
                        asiChild.getListChildren().add(asgChild2);
                        AdvancedSearchItem asiChild2 =
                            new AdvancedSearchItem();
                        asgChild2.getListChildren().add(asiChild2);
                        asiChild2.setItemName("Ma");
                        asiChild2.setRequired(true);
                        asiChild2.getListValue().add(langCode);
                    } catch (Exception e) {
                    }
                }
                Utils.searchadvanced("DlctCbttView2Iterator", listASG);

                listASG = new ArrayList();
                asgTrangThai = new AdvancedSearchGroup();
                listASG.add(asgTrangThai);
                asiTrangThai = new AdvancedSearchItem();
                asgTrangThai.getListChildren().add(asiTrangThai);
                asiTrangThai.setItemName("TrangThai");
                asiTrangThai.setRequired(true);
                asiTrangThai.getListValue().add(0,
                                                new Number(Utils.ENUM_TRANG_THAI.CONG_BO.getId()));
                AdvancedSearchGroup asgLoaiTruongTt =
                    new AdvancedSearchGroup();
                listASG.add(asgLoaiTruongTt);
                AdvancedSearchItem asiLoaiTruongTt = new AdvancedSearchItem();
                asgLoaiTruongTt.getListChildren().add(asiLoaiTruongTt);
                asiLoaiTruongTt.setItemName("DlctLoaiTruongTt");
                asiLoaiTruongTt.setRequired(true);
                asiLoaiTruongTt.getListValue().add(0,
                                                   new Number(Utils.ENUM_LOAI_TRUONG_TT.CONG_BO_THONG_TIN.getId()));
                if (langCode != null) {
                    try {
                        AdvancedSearchGroup asg = new AdvancedSearchGroup();
                        listASG.add(asg);
                        AdvancedSearchItem asi = new AdvancedSearchItem();
                        asg.getListChildren().add(asi);
                        asi.setItemName("DlctNgonNguView");
                        asi.setRequired(true);
                        asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                        AdvancedSearchGroup asgChild =
                            new AdvancedSearchGroup();
                        asi.getListChildren().add(asgChild);
                        AdvancedSearchItem asiChild = new AdvancedSearchItem();
                        asgChild.getListChildren().add(asiChild);
                        asiChild.setItemName("Ma");
                        asiChild.setRequired(true);
                        asiChild.getListValue().add(langCode);
                    } catch (Exception e) {
                    }
                }
                Utils.searchadvanced("DlctTruongTtView1Iterator", listASG);
            }
        }

    }

    public void changePageBaoCao(ActionEvent actionEvent) {
        PortletRequest request =
            (PortletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
        Integer pageNum =
            (Integer)actionEvent.getComponent().getAttributes().get("pageNum");
        if (pageNum == null) {
            pageNum = 1;
        }
        resetIteratorBaoCao(request);
        createFormBaoCao(request, pageNum.intValue());
    }

    private void createFormCbtt(PortletRequest request, int pageNum) {
        danhSachCbttPanel.getChildren().clear();
        searchCbttPanel.getChildren().clear();
        try {
            String loaiDonViId =
                (String)request.getPortletSession().getAttribute("loaidonviid");
            String langCode =
                (String)request.getPortletSession().getAttribute("langcode");
            if (langCode == null) {
                langCode = DEFAULT_LANGCODE;
            }

            String donViRowKey =
                (String)request.getPortletSession().getAttribute("donviid");
            if (donViRowKey != null) {
                DCIteratorBinding donViView1Iterator =
                    Utils.getIteratorBinding("DlctDonViView1Iterator");
                if (donViView1Iterator.findRowByKeyString(donViRowKey) !=
                    null) {
                    donViView1Iterator.setCurrentRowWithKey(donViRowKey);
                    resetPagingCbtt(request, "DlctCbttView2Iterator", pageNum);
                    String chiTietUrl =
                        (String)request.getPortletSession().getAttribute("chitieturl");
                    {
                        SimpleDateFormat dateFormat =
                            new SimpleDateFormat("yyyy/MM/dd");

                        String fromSearch =
                            (String)request.getPortletSession().getAttribute(SEARCH_TU_NGAY);
                        String toSearch =
                            (String)request.getPortletSession().getAttribute(SEARCH_DEN_NGAY);
                        java.util.Date from = null;
                        java.util.Date to = null;
                        if (fromSearch != null) {
                            try {
                                from = dateFormat.parse(fromSearch);
                            } catch (ParseException e) {
                            }
                        }
                        if (toSearch != null) {
                            try {
                                to = dateFormat.parse(toSearch);
                            } catch (ParseException e) {
                            }
                        }

                        DateTimeConverter converter =
                            (DateTimeConverter)FacesContext.getCurrentInstance().getApplication().createConverter("javax.faces.DateTime");
                        converter.setLocale(new Locale(DEFAULT_LANGCODE));
                        converter.setTimeZone(TimeZone.getTimeZone("GMT+7:00"));
                        converter.setType("date");
                        converter.setDateStyle("short");
                        RichInputDate inputDate = new RichInputDate();
                        inputDate.setConverter(converter);
                        inputDate.setId(SEARCH_TU_NGAY);
                        inputDate.setAutoSubmit(true);
                        inputDate.setLabel(getResource("TU_NGAY"));
                        inputDate.setValue(from);
                        searchCbttPanel.getChildren().add(inputDate);
                        inputDate = new RichInputDate();
                        inputDate.setAutoSubmit(true);
                        inputDate.setConverter(converter);
                        inputDate.setId(SEARCH_DEN_NGAY);
                        inputDate.setLabel(getResource("DEN_NGAY"));
                        inputDate.setValue(to);
                        searchCbttPanel.getChildren().add(inputDate);
                        FacesContext fc = FacesContext.getCurrentInstance();
                        Application app = fc.getApplication();
                        ExpressionFactory elFactory =
                            app.getExpressionFactory();
                        ELContext elContext = fc.getELContext();
                        MethodExpression methodExpression =
                            elFactory.createMethodExpression(elContext,
                                                             "#{tongHop.timKiem}",
                                                             null,
                                                             new Class[] { ActionEvent.class });
                        MethodExpressionMethodBinding methodExpressionMethodBinding =
                            new MethodExpressionMethodBinding(methodExpression);
                        RichCommandButton buttonSearch =
                            new RichCommandButton();
                        buttonSearch.setId("searchcbttbutton");
                        buttonSearch.setText(getResource("TIM_KIEM"));
                        buttonSearch.setInlineStyle("margin-bottom:10px;");
                        buttonSearch.getAttributes().put("actionListener",
                                                         methodExpressionMethodBinding);
                        searchCbttPanel.getChildren().add(buttonSearch);
                    }


                    Map<String, String> mapTruongTtRoot = new HashMap();
                    DCIteratorBinding truongTtView1Iterator =
                        Utils.getIteratorBinding("DlctTruongTtView1Iterator");
                    truongTtView1Iterator.setRangeSize(-1);
                    DCIteratorBinding cbttView2Iterator =
                        Utils.getIteratorBinding("DlctCbttView2Iterator");
                    Row[] rows = cbttView2Iterator.getAllRowsInRange();
                    if (rows == null) {
                        rows = new Row[] { };
                    }
                    for (int i = 0; i < rows.length; i++) {
                        cbttView2Iterator.setCurrentRowIndexInRange(i);
                        HashMap<String, Object> mapValue = new HashMap();
                        String rowKey =
                            cbttView2Iterator.getCurrentRow().getKey().toStringFormat(false);
                        mapValue.put(ROW_KEY, rowKey);
                        RowSet rowSetGtTt =
                            (RowSet)cbttView2Iterator.getCurrentRow().getAttribute("DlctGtCbttTtView");
                        if (rowSetGtTt != null) {
                            rowSetGtTt.setRangeSize(-1);
                            Row[] rowsGtTt = rowSetGtTt.getAllRowsInRange();
                            if (rowsGtTt == null) {
                                rowsGtTt = new Row[] { };
                            }
                            for (int j = 0; j < rowsGtTt.length; j++) {
                                Row truongTtRow =
                                    (Row)rowsGtTt[j].getAttribute("DlctTruongTtView");
                                if (truongTtRow != null) {
                                    Number id =
                                        (Number)truongTtRow.getAttribute("Id");
                                    Number kieuDuLieu =
                                        (Number)truongTtRow.getAttribute("KieuDuLieu");
                                    if (id != null && kieuDuLieu != null) {
                                        int kieu = kieuDuLieu.intValue();
                                        if (kieu ==
                                            Utils.ENUM_KIEU_DU_LIEU.NUMBER.getId()) {
                                            Number valNumber =
                                                (Number)rowsGtTt[j].getAttribute("ValNumber");
                                            if (valNumber != null) {
                                                mapValue.put(id.toString(),
                                                             valNumber.toString());
                                            }
                                        }
                                        if (kieu ==
                                            Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId()) {
                                            String valVarchar =
                                                (String)rowsGtTt[j].getAttribute("ValVarchar");
                                            if (valVarchar != null) {
                                                mapValue.put(id.toString(),
                                                             valVarchar);
                                            }
                                        }
                                        if (kieu ==
                                            Utils.ENUM_KIEU_DU_LIEU.LINK.getId()) {
                                            String valVarchar =
                                                (String)rowsGtTt[j].getAttribute("ValVarchar");
                                            if (valVarchar != null) {
                                                String link =
                                                    valVarchar.toLowerCase();
                                                if (link.startsWith("http://") ==
                                                    false) {
                                                    link = "http://" + link;
                                                }
                                                mapValue.put(id.toString() +
                                                             LINK_DES, link);
                                                mapValue.put(id.toString(),
                                                             valVarchar);
                                            }
                                        }
                                        if (kieu ==
                                            Utils.ENUM_KIEU_DU_LIEU.EMAIL.getId()) {
                                            String valVarchar =
                                                (String)rowsGtTt[j].getAttribute("ValVarchar");
                                            if (valVarchar != null) {
                                                String link =
                                                    "mailto:" + valVarchar.toLowerCase();
                                                mapValue.put(id.toString() +
                                                             LINK_DES, link);
                                                mapValue.put(id.toString(),
                                                             valVarchar);
                                            }
                                        }
                                        if (kieu ==
                                            Utils.ENUM_KIEU_DU_LIEU.DATE.getId()) {
                                            oracle.jbo.domain.Date valDate =
                                                (oracle.jbo.domain.Date)rowsGtTt[j].getAttribute("ValDate");
                                            if (valDate != null) {
                                                java.util.Date date =
                                                    valDate.dateValue();
                                                if (date != null) {
                                                    mapValue.put(id.toString(),
                                                                 date);
                                                }
                                            }
                                        }
                                        if (kieu ==
                                            Utils.ENUM_KIEU_DU_LIEU.CLOB.getId()) {
                                            ClobDomain valClob =
                                                (ClobDomain)rowsGtTt[j].getAttribute("ValClob");
                                            if (valClob != null) {
                                                mapValue.put(id.toString(),
                                                             valClob.toString());
                                            }
                                        }
                                        if (kieu ==
                                            Utils.ENUM_KIEU_DU_LIEU.FILE.getId()) {
                                            Row fileViewRow =
                                                (Row)rowsGtTt[j].getAttribute("HtFileView");
                                            if (fileViewRow != null) {
                                                mapValue.put(id.toString(),
                                                             fileViewRow);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        List<UIComponent> listTieuDe = new ArrayList();
                        List<UIComponent> listNgayThang = new ArrayList();
                        List<UIComponent> listTomTat = new ArrayList();

                        Row[] rowsTruongTt =
                            truongTtView1Iterator.getAllRowsInRange();
                        if (rowsTruongTt == null) {
                            rowsTruongTt = new Row[] { };
                        }
                        for (int j = 0; j < rowsTruongTt.length; j++) {
                            String id =
                                ((Number)rowsTruongTt[j].getAttribute("Id")).toString();
                            Number kieuDuLieu =
                                (Number)rowsTruongTt[j].getAttribute("KieuDuLieu");
                            Number viTriHienThi =
                                (Number)rowsTruongTt[j].getAttribute("ViTriHienThi");
                            Row loopRow = rowsTruongTt[j];
                            Row rootRow = null;
                            while (loopRow != null) {
                                rootRow = loopRow;
                                loopRow =
                                        (Row)loopRow.getAttribute("DlctTruongTtTuIdDlctTruongTtView");
                            }
                            String rootId =
                                ((Number)rootRow.getAttribute("Id")).toString();
                            if (viTriHienThi != null && kieuDuLieu != null) {
                                int viTri = viTriHienThi.intValue();
                                int kieu = kieuDuLieu.intValue();
                                mapTruongTtRoot.put(id, rootId);
                                if ((Utils.ENUM_VI_TRI_HIEN_THI.PORTLET_TIN_TIEU_DE.getId() &
                                     viTri) ==
                                    Utils.ENUM_VI_TRI_HIEN_THI.PORTLET_TIN_TIEU_DE.getId()) {
                                    Object obj = mapValue.get(rootId);
                                    if (obj != null) {
                                        RichGoLink goLink = new RichGoLink();
                                        goLink.setTargetFrame("_parent");
                                        goLink.setText(obj.toString());
                                        goLink.setDestination(chiTietUrl +
                                                              "?cbttid=" +
                                                              rowKey +
                                                              (loaiDonViId ==
                                                               null ? "" :
                                                               "&loaidonviid=" +
                                                               loaiDonViId) +
                                                              (langCode ==
                                                               null ? "" :
                                                               "&langcode=" +
                                                               langCode));
                                        listTieuDe.add(goLink);
                                    }

                                }
                                if ((Utils.ENUM_VI_TRI_HIEN_THI.PORTLET_TIN_TOM_TAT.getId() &
                                     viTri) ==
                                    Utils.ENUM_VI_TRI_HIEN_THI.PORTLET_TIN_TOM_TAT.getId()) {
                                    Object obj = mapValue.get(rootId);
                                    if (obj != null) {
                                        if (kieu ==
                                            Utils.ENUM_KIEU_DU_LIEU.NUMBER.getId() ||
                                            kieu ==
                                            Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId() ||
                                            kieu ==
                                            Utils.ENUM_KIEU_DU_LIEU.DATE.getId() ||
                                            kieu ==
                                            Utils.ENUM_KIEU_DU_LIEU.LOAI_CHUNG_KHOAN.getId() ||
                                            kieu ==
                                            Utils.ENUM_KIEU_DU_LIEU.SAN_GIAO_DICH.getId()) {
                                            RichOutputText outputText =
                                                new RichOutputText();
                                            outputText.setValue(obj);
                                            if (kieu ==
                                                Utils.ENUM_KIEU_DU_LIEU.DATE.getId()) {
                                                DateTimeConverter converter =
                                                    (DateTimeConverter)FacesContext.getCurrentInstance().getApplication().createConverter("javax.faces.DateTime");
                                                converter.setLocale(new Locale(langCode));
                                                converter.setTimeZone(TimeZone.getTimeZone("GMT+7:00"));
                                                converter.setType("date");
                                                converter.setDateStyle("short");
                                                outputText.setConverter(converter);
                                            }
                                            listTomTat.add(outputText);
                                        }
                                        if (kieu ==
                                            Utils.ENUM_KIEU_DU_LIEU.CLOB.getId()) {
                                            RichOutputText outputFormatted =
                                                new RichOutputText();
                                            outputFormatted.setEscape(false);
                                            outputFormatted.setValue(obj);
                                            listTomTat.add(outputFormatted);
                                        }
                                        if (kieu ==
                                            Utils.ENUM_KIEU_DU_LIEU.LINK.getId()) {
                                            RichGoLink goLink =
                                                new RichGoLink();
                                            goLink.setTargetFrame("_parent");
                                            goLink.setInlineStyle("padding:5px 7px;");
                                            goLink.setText((String)obj);
                                            String link = (String)obj;
                                            if (link != null) {
                                                link = link.toLowerCase();
                                                if (link.startsWith("http://") ==
                                                    false) {
                                                    link = "http://" + link;
                                                }
                                                goLink.setDestination(link);
                                            }
                                            listTomTat.add(goLink);
                                        }
                                        if (kieu ==
                                            Utils.ENUM_KIEU_DU_LIEU.EMAIL.getId()) {
                                            RichGoLink goLink =
                                                new RichGoLink();
                                            goLink.setTargetFrame("_parent");
                                            goLink.setInlineStyle("padding:5px 7px;");
                                            goLink.setText((String)obj);
                                            goLink.setDestination("mailto:" +
                                                                  obj);
                                            listTomTat.add(goLink);
                                        }
                                        if (kieu ==
                                            Utils.ENUM_KIEU_DU_LIEU.FILE.getId()) {
                                            String htFileServletUrl =
                                                (String)request.getPortletSession().getAttribute("htfileservleturl");
                                            Row row = (Row)obj;
                                            RichGoLink goLink =
                                                new RichGoLink();
                                            goLink.setTargetFrame("_parent");
                                            goLink.setInlineStyle("padding:5px 7px;");
                                            goLink.setText((String)row.getAttribute("TenFile"));
                                            goLink.setDestination(htFileServletUrl +
                                                                  "?id=" +
                                                                  row.getAttribute("Id"));
                                            listTomTat.add(goLink);
                                        }
                                    }

                                }
                            }
                        }

                        RichOutputText outputText=new RichOutputText();
                        outputText.setValue(" (");
                        listNgayThang.add(outputText);
                            Object obj =
                                cbttView2Iterator.getCurrentRow().getAttribute("NgayTao");
                            if (obj != null) {
                                oracle.jbo.domain.Date valDate =
                                    (oracle.jbo.domain.Date)obj;
                                if (valDate != null) {
                                    java.util.Date date = valDate.dateValue();
                                    if (date != null) {
                                        outputText =
                                            new RichOutputText();
                                        outputText.setValue(date);
                                        DateTimeConverter converter =
                                            (DateTimeConverter)FacesContext.getCurrentInstance().getApplication().createConverter("javax.faces.DateTime");
                                        converter.setLocale(new Locale(langCode));
                                        converter.setTimeZone(TimeZone.getTimeZone("GMT+7:00"));
                                        converter.setType("date");
                                        converter.setDateStyle("short");
                                        outputText.setConverter(converter);
                                        listNgayThang.add(outputText);
                                    }
                                }
                            }
                        outputText=new RichOutputText();
                                               outputText.setValue(")");
                                               listNgayThang.add(outputText);
                        RichPanelBorderLayout borderLayout =
                            new RichPanelBorderLayout();
                        RichPanelGroupLayout groupLayout =
                            new RichPanelGroupLayout();
                        groupLayout.setLayout(groupLayout.LAYOUT_VERTICAL);


                        borderLayout.getChildren().addAll(listTieuDe);
                        borderLayout.getChildren().addAll(listNgayThang);
                        groupLayout.getChildren().addAll(listTomTat);
                        danhSachCbttPanel.getChildren().add(borderLayout);
                        danhSachCbttPanel.getChildren().add(groupLayout);
                    }
                }
            }
        } catch (Exception e) {

        }
        AdfFacesContext.getCurrentInstance().addPartialTarget(danhSachCbttPanel);
        AdfFacesContext.getCurrentInstance().partialUpdateNotify(danhSachCbttPanel);
    }

    private void resetPagingCbtt(PortletRequest request, String iteratorName,
                                 int pageNum) {
        FacesContext fc = FacesContext.getCurrentInstance();
        Application app = fc.getApplication();
        ExpressionFactory elFactory = app.getExpressionFactory();
        ELContext elContext = fc.getELContext();
        pagingCbttPanel.getChildren().clear();
        DCIteratorBinding iterator = Utils.getIteratorBinding(iteratorName);
        int rowCount = (int)iterator.getEstimatedRowCount();
        int pageSize =
            DEFAULT_SIZE; //Utils.getPageSize("HtCauHinhView1Iterator");
        try {
            pageSize =
                    Integer.parseInt((String)request.getPortletSession().getAttribute("soluongbanghi"));
        } catch (Exception e) {

        }
        int pageCount = 1;
        if (rowCount > pageSize) {
            if (rowCount % pageSize == 0) {
                pageCount = rowCount / pageSize;
            } else {
                pageCount = rowCount / pageSize + 1;
            }
        }

        if (pageNum < 1) {
            pageNum = 1;
        }
        if (pageNum > pageCount) {
            pageNum = pageCount;
        }
        int first = 1;
        if (pageNum < 3) {
            first = 1;
        } else if (pageNum + 5 > pageCount) {
            if (pageNum + 2 > pageCount) {
                if (pageCount - 4 < 1)
                    first = 1;
                else {
                    first = pageCount - 4;
                }
            } else {
                if (pageCount < 6) {
                    first = 1;
                } else {
                    first = pageNum - 2;
                }
            }
        } else {
            first = pageNum - 2;
        }

        MethodExpression methodExpression =
            elFactory.createMethodExpression(elContext,
                                             "#{tongHop.changePageCbtt}", null,
                                             new Class[] { ActionEvent.class });
        MethodExpressionMethodBinding methodExpressionMethodBinding =
            new MethodExpressionMethodBinding(methodExpression);
        RichCommandLink commandLink = new RichCommandLink();
        commandLink.setPartialSubmit(true);
        commandLink.setText(getResource("PREV"));
        commandLink.getAttributes().put("actionListener",
                                        methodExpressionMethodBinding);
        commandLink.getAttributes().put("pageNum", pageNum - 1);
        commandLink.setInlineStyle("display:block;width:60px;text-align:center;padding-right:3px;");
        pagingCbttPanel.getChildren().add(commandLink);
        if (pageNum == 1) {
            commandLink.setDisabled(true);
        } else {
            commandLink.setDisabled(false);
        }
        if(pageNum>3){
        methodExpression =
            elFactory.createMethodExpression(elContext,
                                             "#{tongHop.changePageCbtt}", null,
                                             new Class[] { ActionEvent.class });
        methodExpressionMethodBinding =
            new MethodExpressionMethodBinding(methodExpression);
            RichCommandLink commandLinkFirst = new RichCommandLink();
            commandLinkFirst.setPartialSubmit(true);
            commandLinkFirst.setText("" +1);
            commandLinkFirst.getAttributes().put("actionListener",
                                            methodExpressionMethodBinding);
            commandLinkFirst.getAttributes().put("pageNum", 1);
                commandLink.setInlineStyle("display:block;padding-right:3px;font-weight:bold;");
            pagingCbttPanel.getChildren().add(commandLinkFirst);
            RichOutputText outputText=new RichOutputText();
            outputText.setValue("...");
            pagingCbttPanel.getChildren().add(outputText);
        }
        for (int i = first, j = 0; i <= pageCount && j < 5; i++, j++) {
            methodExpression =
                    elFactory.createMethodExpression(elContext, "#{tongHop.changePageCbtt}",
                                                     null,
                                                     new Class[] { ActionEvent.class });
            methodExpressionMethodBinding =
                    new MethodExpressionMethodBinding(methodExpression);
            commandLink = new RichCommandLink();
            commandLink.setPartialSubmit(true);
            if (i == pageNum) {
                commandLink.setDisabled(true);
                commandLink.setInlineStyle("display:block;padding-right:3px;font-weight:bold; color:#CCC;");
            } else {
                commandLink.setInlineStyle("display:block;padding-right:3px;font-weight:bold;");
            }
            if(i==pageCount){
            commandLink.setText("" + i+"["+rowCount+"]");
            }else{
                commandLink.setText("" + i);
            }
            commandLink.getAttributes().put("actionListener",
                                            methodExpressionMethodBinding);
            commandLink.getAttributes().put("pageNum", i);
            pagingCbttPanel.getChildren().add(commandLink);
        }
        if (pageNum+2 < pageCount) {
        methodExpression =
                elFactory.createMethodExpression(elContext, "#{tongHop.changePageCbtt}",
                                                 null,
                                                 new Class[] { ActionEvent.class });
        methodExpressionMethodBinding =
                new MethodExpressionMethodBinding(methodExpression);
            RichOutputText outputText=new RichOutputText();
            outputText.setValue("...");
        pagingCbttPanel.getChildren().add(outputText);
            
            RichCommandLink commandLinkLast = new RichCommandLink();
            commandLinkLast.setPartialSubmit(true);
            commandLinkLast.setText("" + pageCount+"["+rowCount+"]");
            commandLinkLast.getAttributes().put("actionListener",
                                            methodExpressionMethodBinding);
            commandLinkLast.getAttributes().put("pageNum", pageCount);
                commandLink.setInlineStyle("display:block;padding-right:3px;font-weight:bold;");
        pagingCbttPanel.getChildren().add(commandLinkLast);
        }
        methodExpression =
                elFactory.createMethodExpression(elContext, "#{tongHop.changePageCbtt}",
                                                 null,
                                                 new Class[] { ActionEvent.class });
        methodExpressionMethodBinding =
                new MethodExpressionMethodBinding(methodExpression);
        commandLink = new RichCommandLink();
        commandLink.setPartialSubmit(true);
        commandLink.setText(getResource("NEXT"));
        commandLink.getAttributes().put("actionListener",
                                        methodExpressionMethodBinding);
        commandLink.getAttributes().put("pageNum", pageNum + 1);
        commandLink.setInlineStyle("display:block;width:60px;text-align:center;padding-right:3px;");
        pagingCbttPanel.getChildren().add(commandLink);
        if (pageNum == pageCount) {
            commandLink.setDisabled(true);
        } else {
            commandLink.setDisabled(false);
        }

        iterator.executeQuery();
        if ((pageNum) * pageSize > rowCount) {
            iterator.setRangeSize(rowCount - (pageNum - 1) * pageSize);
        } else {
            iterator.setRangeSize(pageSize);
        }
        iterator.setRangeStart((pageNum - 1) * pageSize);

        AdfFacesContext.getCurrentInstance().addPartialTarget(pagingCbttPanel);
    }

    private void resetIteratorCbtt(PortletRequest request) {
        String loaiDonViId =
            (String)request.getPortletSession().getAttribute("loaidonviid");
        String langCode =
            (String)request.getPortletSession().getAttribute("langcode");
        if (langCode == null) {
            langCode = DEFAULT_LANGCODE;
        }
        {
            List<AdvancedSearchGroup> listASG = new ArrayList();
            AdvancedSearchGroup asgTrangThai = new AdvancedSearchGroup();
            listASG.add(asgTrangThai);
            AdvancedSearchItem asiTrangThai = new AdvancedSearchItem();
            asgTrangThai.getListChildren().add(asiTrangThai);
            asiTrangThai.setItemName("TrangThai");
            asiTrangThai.setRequired(true);
            asiTrangThai.getListValue().add(0,
                                            new Number(Utils.ENUM_TRANG_THAI.CONG_BO.getId()));
            if (loaiDonViId != null) {
                try {
                    Number loaiDonViNumber = new Number(loaiDonViId);
                    AdvancedSearchGroup asg = new AdvancedSearchGroup();
                    listASG.add(asg);
                    AdvancedSearchItem asi = new AdvancedSearchItem();
                    asg.getListChildren().add(asi);
                    asi.setItemName("DlctDvLdvView");
                    asi.setRequired(true);
                    asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                    AdvancedSearchGroup asgChild = new AdvancedSearchGroup();
                    asi.getListChildren().add(asgChild);
                    AdvancedSearchItem asiChild = new AdvancedSearchItem();
                    asgChild.getListChildren().add(asiChild);
                    asiChild.setItemName("DlctLoaiDonViId");
                    asiChild.setRequired(true);
                    asiChild.getListValue().add(loaiDonViNumber);
                } catch (Exception e) {
                }
            }
            if (langCode != null) {
                try {
                    AdvancedSearchGroup asg = new AdvancedSearchGroup();
                    listASG.add(asg);
                    AdvancedSearchItem asi = new AdvancedSearchItem();
                    asg.getListChildren().add(asi);
                    asi.setItemName("DlctDvNnView");
                    asi.setRequired(true);
                    asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                    AdvancedSearchGroup asgChild = new AdvancedSearchGroup();
                    asi.getListChildren().add(asgChild);
                    AdvancedSearchItem asiChild = new AdvancedSearchItem();
                    asgChild.getListChildren().add(asiChild);
                    asiChild.setItemName("DlctNgonNguView");
                    asiChild.setRequired(true);
                    asiChild.setOperator(AdvancedSearchItem.OPER_EXISTS);
                    AdvancedSearchGroup asgChild2 = new AdvancedSearchGroup();
                    asiChild.getListChildren().add(asgChild2);
                    AdvancedSearchItem asiChild2 = new AdvancedSearchItem();
                    asgChild2.getListChildren().add(asiChild2);
                    asiChild2.setItemName("Ma");
                    asiChild2.setRequired(true);
                    asiChild2.getListValue().add(langCode);
                } catch (Exception e) {
                }
            }
            Utils.searchadvanced("DlctDonViView1Iterator", listASG);
        }

        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
        String fromSearch =
            (String)request.getPortletSession().getAttribute(SEARCH_TU_NGAY);
        String toSearch =
            (String)request.getPortletSession().getAttribute(SEARCH_DEN_NGAY);
        java.util.Date tuNgay = null;
        java.util.Date denNgay = null;
        if (fromSearch != null) {
            try {
                tuNgay = dateFormat.parse(fromSearch);
            } catch (ParseException e) {
            }
        }
        if (toSearch != null) {
            try {
                denNgay = dateFormat.parse(toSearch);
            } catch (ParseException e) {
            }
        }
        String donViRowKey =
            (String)request.getPortletSession().getAttribute("donviid");
        if (donViRowKey != null) {
            DCIteratorBinding donViView1Iterator =
                Utils.getIteratorBinding("DlctDonViView1Iterator");
            if (donViView1Iterator.findRowByKeyString(donViRowKey) != null) {
                donViView1Iterator.setCurrentRowWithKey(donViRowKey);

                List<AdvancedSearchGroup> listASG = new ArrayList();
                AdvancedSearchGroup asgTrangThai = new AdvancedSearchGroup();
                listASG.add(asgTrangThai);
                AdvancedSearchItem asiTrangThai = new AdvancedSearchItem();
                asgTrangThai.getListChildren().add(asiTrangThai);
                asiTrangThai.setItemName("TrangThai");
                asiTrangThai.setRequired(true);
                asiTrangThai.getListValue().add(0,
                                                new Number(Utils.ENUM_TRANG_THAI.CONG_BO.getId()));

                if (tuNgay != null) {
                    AdvancedSearchGroup asg = new AdvancedSearchGroup();
                    listASG.add(asg);
                    AdvancedSearchItem asi = new AdvancedSearchItem();
                    asg.getListChildren().add(asi);
                    asi.setItemName("NgayTao");
                    asi.setOperator(AdvancedSearchItem.OPER_ON_OR_AFTER);
                    asi.getListValue().add(new oracle.jbo.domain.Date(new Timestamp(tuNgay.getTime())));
                }
                if (denNgay != null) {
                    AdvancedSearchGroup asg = new AdvancedSearchGroup();
                    listASG.add(asg);
                    AdvancedSearchItem asi = new AdvancedSearchItem();
                    asg.getListChildren().add(asi);
                    asi.setItemName("NgayTao");
                    asi.setOperator(AdvancedSearchItem.OPER_ON_OR_BEFORE);
                    asi.getListValue().add(new oracle.jbo.domain.Date(new Timestamp(denNgay.getTime())));
                }
                try {
                    AdvancedSearchGroup asg = new AdvancedSearchGroup();
                    listASG.add(asg);
                    AdvancedSearchItem asi = new AdvancedSearchItem();
                    asg.getListChildren().add(asi);
                    asi.setItemName("DlctLoaiCbttView");
                    asi.setRequired(true);
                    asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                    AdvancedSearchGroup asgChild = new AdvancedSearchGroup();
                    asi.getListChildren().add(asgChild);
                    AdvancedSearchItem asiChild = new AdvancedSearchItem();
                    asgChild.getListChildren().add(asiChild);
                    asiChild.setItemName("BaoCao");
                    asiChild.setRequired(true);
                    asiChild.setOperator(AdvancedSearchItem.OPER_IN);
                    asiChild.getListValue().add(new Number(Utils.ENUM_BAO_CAO.KHONG_PHAI_BAO_CAO.getId()));
                } catch (Exception e) {
                }
                if (langCode != null) {
                    try {
                        AdvancedSearchGroup asg = new AdvancedSearchGroup();
                        listASG.add(asg);
                        AdvancedSearchItem asi = new AdvancedSearchItem();
                        asg.getListChildren().add(asi);
                        asi.setItemName("DlctCbttNnView");
                        asi.setRequired(true);
                        asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                        AdvancedSearchGroup asgChild =
                            new AdvancedSearchGroup();
                        asi.getListChildren().add(asgChild);
                        AdvancedSearchItem asiChild = new AdvancedSearchItem();
                        asgChild.getListChildren().add(asiChild);
                        asiChild.setItemName("DlctNgonNguView");
                        asiChild.setRequired(true);
                        asiChild.setOperator(AdvancedSearchItem.OPER_EXISTS);
                        AdvancedSearchGroup asgChild2 =
                            new AdvancedSearchGroup();
                        asiChild.getListChildren().add(asgChild2);
                        AdvancedSearchItem asiChild2 =
                            new AdvancedSearchItem();
                        asgChild2.getListChildren().add(asiChild2);
                        asiChild2.setItemName("Ma");
                        asiChild2.setRequired(true);
                        asiChild2.getListValue().add(langCode);
                    } catch (Exception e) {
                    }
                }
                Utils.searchadvanced("DlctCbttView2Iterator", listASG);

                listASG = new ArrayList();
                asgTrangThai = new AdvancedSearchGroup();
                listASG.add(asgTrangThai);
                asiTrangThai = new AdvancedSearchItem();
                asgTrangThai.getListChildren().add(asiTrangThai);
                asiTrangThai.setItemName("TrangThai");
                asiTrangThai.setRequired(true);
                asiTrangThai.getListValue().add(0,
                                                new Number(Utils.ENUM_TRANG_THAI.CONG_BO.getId()));
                AdvancedSearchGroup asgLoaiTruongTt =
                    new AdvancedSearchGroup();
                listASG.add(asgLoaiTruongTt);
                AdvancedSearchItem asiLoaiTruongTt = new AdvancedSearchItem();
                asgLoaiTruongTt.getListChildren().add(asiLoaiTruongTt);
                asiLoaiTruongTt.setItemName("DlctLoaiTruongTt");
                asiLoaiTruongTt.setRequired(true);
                asiLoaiTruongTt.getListValue().add(0,
                                                   new Number(Utils.ENUM_LOAI_TRUONG_TT.CONG_BO_THONG_TIN.getId()));
                if (langCode != null) {
                    try {
                        AdvancedSearchGroup asg = new AdvancedSearchGroup();
                        listASG.add(asg);
                        AdvancedSearchItem asi = new AdvancedSearchItem();
                        asg.getListChildren().add(asi);
                        asi.setItemName("DlctNgonNguView");
                        asi.setRequired(true);
                        asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                        AdvancedSearchGroup asgChild =
                            new AdvancedSearchGroup();
                        asi.getListChildren().add(asgChild);
                        AdvancedSearchItem asiChild = new AdvancedSearchItem();
                        asgChild.getListChildren().add(asiChild);
                        asiChild.setItemName("Ma");
                        asiChild.setRequired(true);
                        asiChild.getListValue().add(langCode);
                    } catch (Exception e) {
                    }
                }
                Utils.searchadvanced("DlctTruongTtView1Iterator", listASG);
            }
        }
    }

    public void changePageCbtt(ActionEvent actionEvent) {
        PortletRequest request =
            (PortletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
        Integer pageNum =
            (Integer)actionEvent.getComponent().getAttributes().get("pageNum");
        if (pageNum == null) {
            pageNum = 1;
        }
        resetIteratorCbtt(request);
        createFormCbtt(request, pageNum.intValue());
    }

    public void resetChiTiet(DisclosureEvent disclosureEvent) {
        if (disclosureEvent.isExpanded()) {
            PortletRequest request =
                (PortletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
            resetIteratorChiTiet(request);
            createFormChiTiet(request, getValueChiTiet(request));
        }
    }

    public void changeNamBaoCao(ValueChangeEvent valueChangeEvent) {
        PortletRequest request =
            (PortletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
        request.getPortletSession().setAttribute("year",
                                                 valueChangeEvent.getNewValue());
        resetIteratorBaoCao(request);
        createFormBaoCao(request, 0);
        AdfFacesContext.getCurrentInstance().addPartialTarget(tableBaoCao);
        AdfFacesContext.getCurrentInstance().addPartialTarget(pagingBaoCaoPanel);
    }

    public void timKiem(ActionEvent actionEvent) {
        PortletRequest request =
            (PortletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
        RichInputDate inputFrom = null;
        RichInputDate inputTo = null;
        List<UIComponent> listChild = searchCbttPanel.getChildren();
        for (UIComponent uiComponent : listChild) {
            if (uiComponent != null && uiComponent instanceof RichInputDate) {
                if (SEARCH_TU_NGAY.equals(uiComponent.getId())) {
                    inputFrom = (RichInputDate)uiComponent;
                } else if (SEARCH_DEN_NGAY.equals(uiComponent.getId())) {
                    inputTo = (RichInputDate)uiComponent;
                }
            }
        }
        if (inputFrom != null && inputFrom.getValue() != null) {
            if (inputTo != null && inputTo.getValue() != null) {
                java.util.Date from = (java.util.Date)inputFrom.getValue();
                java.util.Date to = (java.util.Date)inputTo.getValue();
                request.getPortletSession().setAttribute(SEARCH_TU_NGAY,
                                                         dateFormat.format(from));
                request.getPortletSession().setAttribute(SEARCH_DEN_NGAY,
                                                         dateFormat.format(to));
            } else {
                request.getPortletSession().setAttribute(SEARCH_TU_NGAY,
                                                         dateFormat.format((java.util.Date)inputFrom.getValue()));
                request.getPortletSession().setAttribute(SEARCH_DEN_NGAY,
                                                         null);

            }
        } else if (inputTo != null && inputTo.getValue() != null) {
            request.getPortletSession().setAttribute(SEARCH_TU_NGAY, null);
            request.getPortletSession().setAttribute(SEARCH_DEN_NGAY,
                                                     dateFormat.format((java.util.Date)inputTo.getValue()));
        }else{
            request.getPortletSession().setAttribute(SEARCH_TU_NGAY, null);
            request.getPortletSession().setAttribute(SEARCH_DEN_NGAY,null);
        }
        request.getPortletSession().setAttribute("resettabbed", 0);
        resetIteratorCbtt(request);
        createFormCbtt(request, 0);
        AdfFacesContext.getCurrentInstance().addPartialTarget(danhSachCbttPanel);
        AdfFacesContext.getCurrentInstance().addPartialTarget(pagingCbttPanel);
    }

    public void resetBaoCao(DisclosureEvent disclosureEvent) {
            PortletRequest request =
                (PortletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
            request.getPortletSession().setAttribute("year",
                                                     null);
            request.getPortletSession().setAttribute(SEARCH_TU_NGAY, null);
            request.getPortletSession().setAttribute(SEARCH_DEN_NGAY,null);
        if (disclosureEvent.isExpanded()) {
            request.getPortletSession().setAttribute("year", null);
            resetIteratorBaoCao(request);
            createFormBaoCao(request, 0);
            AdfFacesContext.getCurrentInstance().addPartialTarget(tableBaoCao);
            AdfFacesContext.getCurrentInstance().addPartialTarget(pagingBaoCaoPanel);
        }
    }

    public void resetCbtt(DisclosureEvent disclosureEvent) {
            PortletRequest request =
                (PortletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
            request.getPortletSession().setAttribute("year",
                                                     null);
            request.getPortletSession().setAttribute(SEARCH_TU_NGAY, null);
            request.getPortletSession().setAttribute(SEARCH_DEN_NGAY,null);
        if (disclosureEvent.isExpanded()) {
            resetIteratorCbtt(request);
            createFormCbtt(request, 0);
            AdfFacesContext.getCurrentInstance().addPartialTarget(danhSachCbttPanel);
            AdfFacesContext.getCurrentInstance().addPartialTarget(pagingCbttPanel);
        }
    }

    private String getResource(String resourceKey) {
        PortletRequest request =
            (PortletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
        String langCode =
            (String)request.getPortletSession().getAttribute("langcode");
        if (langCode == null) {
            langCode = DEFAULT_LANGCODE;
        }
        Locale locale = new Locale(langCode);
        ResourceBundle bundle =
            ResourceBundle.getBundle("portlet.tonghop.resource.TongHopBundle",
                                     locale);
        return bundle.getString(resourceKey);
    }

    public String getTieuDe() {
        PortletRequest request =
            (PortletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
        return request.getParameter("tieude");
    }

    public String getHoSoDoanhNghiep() {
        return getResource("HO_SO_DOANH_NGHIEP");
    }

    public String getBaoCaoTaiChinh() {
        return getResource("BAO_CAO_TAI_CHINH");
    }

    public String getCongBoThongTin() {
        return getResource("CONG_BO_THONG_TIN");
    }

    public void setChiTietPanel(RichPanelFormLayout chiTietPanel) {
        this.chiTietPanel = chiTietPanel;
    }

    public RichPanelFormLayout getChiTietPanel() {
        return chiTietPanel;
    }

    public void setSearchBaoCaoPanel(RichPanelFormLayout searchBaoCaoPanel) {
        this.searchBaoCaoPanel = searchBaoCaoPanel;
    }

    public RichPanelFormLayout getSearchBaoCaoPanel() {
        return searchBaoCaoPanel;
    }

    public void setSearchCbttPanel(RichPanelFormLayout searchCbttPanel) {
        this.searchCbttPanel = searchCbttPanel;
    }

    public RichPanelFormLayout getSearchCbttPanel() {
        return searchCbttPanel;
    }

    public void setPagingBaoCaoPanel(RichPanelGroupLayout pagingBaoCaoPanel) {
        this.pagingBaoCaoPanel = pagingBaoCaoPanel;
    }

    public RichPanelGroupLayout getPagingBaoCaoPanel() {
        return pagingBaoCaoPanel;
    }

    public void setDanhSachCbttPanel(RichPanelGroupLayout danhSachCbttPanel) {
        this.danhSachCbttPanel = danhSachCbttPanel;
    }

    public RichPanelGroupLayout getDanhSachCbttPanel() {
        return danhSachCbttPanel;
    }

    public void setPagingCbttPanel(RichPanelGroupLayout pagingCbttPanel) {
        this.pagingCbttPanel = pagingCbttPanel;
    }

    public RichPanelGroupLayout getPagingCbttPanel() {
        return pagingCbttPanel;
    }

    public void setTableBaoCao(RichTable tableBaoCao) {
        this.tableBaoCao = tableBaoCao;
    }

    public RichTable getTableBaoCao() {
        return tableBaoCao;
    }

    public void setOutputTextTenDonVi(RichOutputText outputTextTenDonVi) {
        this.outputTextTenDonVi = outputTextTenDonVi;
    }

    public RichOutputText getOutputTextTenDonVi() {
        return outputTextTenDonVi;
    }

    public void setTabbedTongHop(RichPanelTabbed tabbedTongHop) {
        this.tabbedTongHop = tabbedTongHop;
    }

    public RichPanelTabbed getTabbedTongHop() {
        return tabbedTongHop;
    }

    public static class ThoiGianComparator implements Comparator<Map<String, Object>> {

        public int compare(Map<String, Object> o1, Map<String, Object> o2) {
            if (o1 != null && o2 != null) {
                Object thoiGian1 = o1.get("ThoiGian");
                Object thoiGian2 = o1.get("ThoiGian");
                if (thoiGian1 instanceof java.util.Date &&
                    thoiGian2 instanceof java.util.Date)
                    if (thoiGian1 != null && thoiGian2 != null) {
                        return ((java.util.Date)thoiGian1).compareTo((java.util.Date)thoiGian2);
                    } else if (thoiGian1 != null) {
                        return -1;
                    } else if (thoiGian2 != null) {
                        return 1;
                    }
            } else if (o1 != null) {
                return -1;
            } else if (o2 != null) {
                return 1;
            }
            return 0;
        }
    }
}
